Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #21435 -- Improved error message when urlconf is empty.

The new error message now hints that the most likely issue
is a circular import.

Thanks to trac user elena for the report and to
bpeschier for the original patch.
  • Loading branch information...
commit 173aa5199737c60ab883a0469684e83c01604ce8 1 parent d399731
@bmispelon bmispelon authored
Showing with 11 additions and 3 deletions.
  1. +7 −1 django/core/urlresolvers.py
  2. +4 −2 tests/urlpatterns_reverse/tests.py
View
8 django/core/urlresolvers.py
@@ -346,11 +346,17 @@ def urlconf_module(self):
@property
def url_patterns(self):
+ # urlconf_module might be a valid set of patterns, so we default to it
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
try:
iter(patterns)
except TypeError:
- raise ImproperlyConfigured("The included urlconf %s doesn't have any patterns in it" % self.urlconf_name)
+ msg = (
+ "The included urlconf '{name}' does not appear to have any "
+ "patterns in it. If you see valid patterns in the file then "
+ "the issue is probably caused by a circular import."
+ )
+ raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
return patterns
def _resolve_special(self, view_type):
View
6 tests/urlpatterns_reverse/tests.py
@@ -161,8 +161,10 @@ def test_no_urls_exception(self):
resolver = RegexURLResolver(r'^$', self.urls)
self.assertRaisesMessage(ImproperlyConfigured,
- "The included urlconf urlpatterns_reverse.no_urls "
- "doesn't have any patterns in it", getattr, resolver, 'url_patterns')
+ "The included urlconf 'urlpatterns_reverse.no_urls' does not "
+ "appear to have any patterns in it. If you see valid patterns in "
+ "the file then the issue is probably caused by a circular import.",
+ getattr, resolver, 'url_patterns')
class URLPatternReverse(TestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.