More helpful exception when URL cannot reverse and field value was empty. Closes #2698.

This commit is contained in:
Tom Christie 2015-07-02 11:36:14 +01:00
parent c4f908d4ee
commit 055986b5b0

View File

@ -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)