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
This commit is contained in:
parent
54618dc0fe
commit
85c369001b
|
@ -128,15 +128,21 @@ def technical_404_response(request, exception):
|
||||||
Create a technical 404 error response. The exception should be the Http404
|
Create a technical 404 error response. The exception should be the Http404
|
||||||
exception.
|
exception.
|
||||||
"""
|
"""
|
||||||
|
urlconf_is_empty = False
|
||||||
try:
|
try:
|
||||||
tried = exception.args[0]['tried']
|
tried = exception.args[0]['tried']
|
||||||
except (IndexError, TypeError):
|
except (IndexError, TypeError):
|
||||||
tried = []
|
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)
|
t = Template(TECHNICAL_404_TEMPLATE)
|
||||||
c = Context({
|
c = Context({
|
||||||
'root_urlconf': settings.ROOT_URLCONF,
|
'root_urlconf': settings.ROOT_URLCONF,
|
||||||
'urlpatterns': tried,
|
'urlpatterns': tried,
|
||||||
|
'urlconf_is_empty': urlconf_is_empty,
|
||||||
'reason': str(exception),
|
'reason': str(exception),
|
||||||
'request': request,
|
'request': request,
|
||||||
'request_protocol': os.environ.get("HTTPS") == "on" and "https" or "http",
|
'request_protocol': os.environ.get("HTTPS") == "on" and "https" or "http",
|
||||||
|
@ -533,19 +539,23 @@ TECHNICAL_404_TEMPLATE = """
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div id="info">
|
<div id="info">
|
||||||
{% if urlpatterns %}
|
{% if urlconf_is_empty %}
|
||||||
<p>
|
<p>Your URLconf, <code>{{ settings.ROOT_URLCONF }}</code>, was empty.</p>
|
||||||
|
{% else %}
|
||||||
|
{% if urlpatterns %}
|
||||||
|
<p>
|
||||||
Using the URLconf defined in <code>{{ settings.ROOT_URLCONF }}</code>,
|
Using the URLconf defined in <code>{{ settings.ROOT_URLCONF }}</code>,
|
||||||
Django tried these URL patterns, in this order:
|
Django tried these URL patterns, in this order:
|
||||||
</p>
|
</p>
|
||||||
<ol>
|
<ol>
|
||||||
{% for pattern in urlpatterns %}
|
{% for pattern in urlpatterns %}
|
||||||
<li>{{ pattern|escape }}</li>
|
<li>{{ pattern|escape }}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ol>
|
</ol>
|
||||||
<p>The current URL, <code>{{ request.path }}</code>, didn't match any of these.</p>
|
<p>The current URL, <code>{{ request.path }}</code>, didn't match any of these.</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>{{ reason|escape }}</p>
|
<p>{{ reason|escape }}</p>
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue