From 055986b5b09573758d32637adf627f737e50edb2 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 2 Jul 2015 11:36:14 +0100 Subject: [PATCH] More helpful exception when URL cannot reverse and field value was empty. Closes #2698. --- rest_framework/relations.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rest_framework/relations.py b/rest_framework/relations.py index 549aa85c0..c5cbfebcd 100644 --- a/rest_framework/relations.py +++ b/rest_framework/relations.py @@ -282,6 +282,13 @@ class HyperlinkedRelatedField(RelatedField): 'model in your API, or incorrectly configured the ' '`lookup_field` attribute on this field.' ) + if value in ('', None): + value_string = {'': 'the empty string', None: 'None'}[value] + msg += ( + " WARNING: The value of the field on the model instance " + "was %s, which may be why it didn't match any " + "entries in your URL conf." % value_string + ) raise ImproperlyConfigured(msg % self.view_name)