Fixed #12083: Ensured generating debug 404 page won't raise a key error. Thanks pigletto.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12679 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Karen Tracey 2010-03-05 18:53:07 +00:00
parent 0a0748a7d6
commit eb11229ba7
4 changed files with 12 additions and 3 deletions

View File

@ -268,7 +268,7 @@ 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."
try: try:
tried = exception.args[0]['tried'] tried = exception.args[0]['tried']
except (IndexError, TypeError): except (IndexError, TypeError, KeyError):
tried = [] tried = []
else: else:
if not tried: if not tried:

View File

@ -19,3 +19,7 @@ class DebugViewTests(TestCase):
response = self.client.post('/views/raises/', data) response = self.client.post('/views/raises/', data)
self.failUnless('file_data.txt' in response.content) self.failUnless('file_data.txt' in response.content)
self.failIf('haha' in response.content) self.failIf('haha' in response.content)
def test_404(self):
response = self.client.get('/views/raises404/')
self.assertEquals(response.status_code, 404)

View File

@ -95,7 +95,8 @@ urlpatterns += patterns('django.views.generic.create_update',
# a view that raises an exception for the debug view # a view that raises an exception for the debug view
urlpatterns += patterns('', urlpatterns += patterns('',
(r'^raises/$', views.raises) (r'^raises/$', views.raises),
(r'^raises404/$', views.raises404),
) )
# rediriects, both temporary and permanent, with non-ASCII targets # rediriects, both temporary and permanent, with non-ASCII targets

View File

@ -4,6 +4,7 @@ from django.http import HttpResponse, HttpResponseRedirect
from django import forms from django import forms
from django.views.debug import technical_500_response from django.views.debug import technical_500_response
from django.views.generic.create_update import create_object from django.views.generic.create_update import create_object
from django.core.urlresolvers import get_resolver
from models import Article from models import Article
@ -12,7 +13,6 @@ def index_page(request):
"""Dummy index page""" """Dummy index page"""
return HttpResponse('<html><body>Dummy page</body></html>') return HttpResponse('<html><body>Dummy page</body></html>')
def custom_create(request): def custom_create(request):
""" """
Calls create_object generic view with a custom form class. Calls create_object generic view with a custom form class.
@ -37,6 +37,10 @@ def raises(request):
except Exception: except Exception:
return technical_500_response(request, *sys.exc_info()) return technical_500_response(request, *sys.exc_info())
def raises404(request):
resolver = get_resolver(None)
resolver.resolve('')
def redirect(request): def redirect(request):
""" """
Forces an HTTP redirect. Forces an HTTP redirect.