From 85c369001b750909e616470cb853ceb2301fd71a Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 6 Dec 2005 05:04:56 +0000 Subject: [PATCH] Debug 400 page now displays special error message if your URLconf is empty. git-svn-id: http://code.djangoproject.com/svn/django/trunk@1552 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/views/debug.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/django/views/debug.py b/django/views/debug.py index 863651b538..8909c1f64f 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -128,15 +128,21 @@ def technical_404_response(request, exception): Create a technical 404 error response. The exception should be the Http404 exception. """ + urlconf_is_empty = False try: tried = exception.args[0]['tried'] except (IndexError, TypeError): tried = [] + else: + if not tried: + # tried exists but is an empty list. The URLconf must've been empty. + urlconf_is_empty = True t = Template(TECHNICAL_404_TEMPLATE) c = Context({ 'root_urlconf': settings.ROOT_URLCONF, 'urlpatterns': tried, + 'urlconf_is_empty': urlconf_is_empty, 'reason': str(exception), 'request': request, 'request_protocol': os.environ.get("HTTPS") == "on" and "https" or "http", @@ -533,19 +539,23 @@ TECHNICAL_404_TEMPLATE = """
- {% if urlpatterns %} -

+ {% if urlconf_is_empty %} +

Your URLconf, {{ settings.ROOT_URLCONF }}, was empty.

+ {% else %} + {% if urlpatterns %} +

Using the URLconf defined in {{ settings.ROOT_URLCONF }}, Django tried these URL patterns, in this order: -

-
    - {% for pattern in urlpatterns %} -
  1. {{ pattern|escape }}
  2. - {% endfor %} -
-

The current URL, {{ request.path }}, didn't match any of these.

- {% else %} -

{{ reason|escape }}

+

+
    + {% for pattern in urlpatterns %} +
  1. {{ pattern|escape }}
  2. + {% endfor %} +
+

The current URL, {{ request.path }}, didn't match any of these.

+ {% else %} +

{{ reason|escape }}

+ {% endif %} {% endif %}