Fixed #32870 -- Improved error message when URLconf is empty.

This commit is contained in:
Igor Fernandes 2021-05-26 16:06:47 -03:00 committed by Mariusz Felisiak
parent ee408309d2
commit e85d9c02ad
2 changed files with 10 additions and 7 deletions

View File

@ -626,9 +626,10 @@ class URLResolver:
iter(patterns) iter(patterns)
except TypeError as e: except TypeError as e:
msg = ( msg = (
"The included URLconf '{name}' does not appear to have any " "The included URLconf '{name}' does not appear to have "
"patterns in it. If you see valid patterns in the file then " "any patterns in it. If you see the 'urlpatterns' variable "
"the issue is probably caused by a circular import." "with valid patterns in the file then the issue is probably "
"caused by a circular import."
) )
raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
return patterns return patterns

View File

@ -271,8 +271,9 @@ class NoURLPatternsTests(SimpleTestCase):
with self.assertRaisesMessage( with self.assertRaisesMessage(
ImproperlyConfigured, ImproperlyConfigured,
"The included URLconf 'urlpatterns_reverse.no_urls' does not " "The included URLconf 'urlpatterns_reverse.no_urls' does not "
"appear to have any patterns in it. If you see valid patterns in " "appear to have any patterns in it. If you see the 'urlpatterns' "
"the file then the issue is probably caused by a circular import." "variable with valid patterns in the file then the issue is "
"probably caused by a circular import."
): ):
getattr(resolver, 'url_patterns') getattr(resolver, 'url_patterns')
@ -1095,8 +1096,9 @@ class NoRootUrlConfTests(SimpleTestCase):
def test_no_handler_exception(self): def test_no_handler_exception(self):
msg = ( msg = (
"The included URLconf 'None' does not appear to have any patterns " "The included URLconf 'None' does not appear to have any patterns "
"in it. If you see valid patterns in the file then the issue is " "in it. If you see the 'urlpatterns' variable with valid patterns "
"probably caused by a circular import." "in the file then the issue is probably caused by a circular "
"import."
) )
with self.assertRaisesMessage(ImproperlyConfigured, msg): with self.assertRaisesMessage(ImproperlyConfigured, msg):
self.client.get('/test/me/') self.client.get('/test/me/')