From e85d9c02ad1ef8988c149bad905fbc5b98a38594 Mon Sep 17 00:00:00 2001 From: Igor Fernandes Date: Wed, 26 May 2021 16:06:47 -0300 Subject: [PATCH] Fixed #32870 -- Improved error message when URLconf is empty. --- django/urls/resolvers.py | 7 ++++--- tests/urlpatterns_reverse/tests.py | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/django/urls/resolvers.py b/django/urls/resolvers.py index 674fd0c58e..3a53bce1de 100644 --- a/django/urls/resolvers.py +++ b/django/urls/resolvers.py @@ -626,9 +626,10 @@ class URLResolver: iter(patterns) except TypeError as e: 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." + "The included URLconf '{name}' does not appear to have " + "any patterns in it. If you see the 'urlpatterns' variable " + "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 return patterns diff --git a/tests/urlpatterns_reverse/tests.py b/tests/urlpatterns_reverse/tests.py index 7190023d3a..f2102c5304 100644 --- a/tests/urlpatterns_reverse/tests.py +++ b/tests/urlpatterns_reverse/tests.py @@ -271,8 +271,9 @@ class NoURLPatternsTests(SimpleTestCase): with self.assertRaisesMessage( ImproperlyConfigured, "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." + "appear to have any patterns in it. If you see the 'urlpatterns' " + "variable with valid patterns in the file then the issue is " + "probably caused by a circular import." ): getattr(resolver, 'url_patterns') @@ -1095,8 +1096,9 @@ class NoRootUrlConfTests(SimpleTestCase): def test_no_handler_exception(self): msg = ( "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 " - "probably caused by a circular import." + "in it. If you see the 'urlpatterns' variable with valid patterns " + "in the file then the issue is probably caused by a circular " + "import." ) with self.assertRaisesMessage(ImproperlyConfigured, msg): self.client.get('/test/me/')