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:
parent
0a0748a7d6
commit
eb11229ba7
|
@ -268,7 +268,7 @@ def technical_404_response(request, exception):
|
|||
"Create a technical 404 error response. The exception should be the Http404."
|
||||
try:
|
||||
tried = exception.args[0]['tried']
|
||||
except (IndexError, TypeError):
|
||||
except (IndexError, TypeError, KeyError):
|
||||
tried = []
|
||||
else:
|
||||
if not tried:
|
||||
|
|
|
@ -19,3 +19,7 @@ class DebugViewTests(TestCase):
|
|||
response = self.client.post('/views/raises/', data)
|
||||
self.failUnless('file_data.txt' 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)
|
||||
|
|
|
@ -95,7 +95,8 @@ urlpatterns += patterns('django.views.generic.create_update',
|
|||
|
||||
# a view that raises an exception for the debug view
|
||||
urlpatterns += patterns('',
|
||||
(r'^raises/$', views.raises)
|
||||
(r'^raises/$', views.raises),
|
||||
(r'^raises404/$', views.raises404),
|
||||
)
|
||||
|
||||
# rediriects, both temporary and permanent, with non-ASCII targets
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.http import HttpResponse, HttpResponseRedirect
|
|||
from django import forms
|
||||
from django.views.debug import technical_500_response
|
||||
from django.views.generic.create_update import create_object
|
||||
from django.core.urlresolvers import get_resolver
|
||||
|
||||
from models import Article
|
||||
|
||||
|
@ -12,7 +13,6 @@ def index_page(request):
|
|||
"""Dummy index page"""
|
||||
return HttpResponse('<html><body>Dummy page</body></html>')
|
||||
|
||||
|
||||
def custom_create(request):
|
||||
"""
|
||||
Calls create_object generic view with a custom form class.
|
||||
|
@ -37,6 +37,10 @@ def raises(request):
|
|||
except Exception:
|
||||
return technical_500_response(request, *sys.exc_info())
|
||||
|
||||
def raises404(request):
|
||||
resolver = get_resolver(None)
|
||||
resolver.resolve('')
|
||||
|
||||
def redirect(request):
|
||||
"""
|
||||
Forces an HTTP redirect.
|
||||
|
|
Loading…
Reference in New Issue