diff --git a/django/views/debug.py b/django/views/debug.py index e4e23f2563..6604bd3dae 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -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: diff --git a/tests/regressiontests/views/tests/debug.py b/tests/regressiontests/views/tests/debug.py index 0c0b62f51f..5431c19932 100644 --- a/tests/regressiontests/views/tests/debug.py +++ b/tests/regressiontests/views/tests/debug.py @@ -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) diff --git a/tests/regressiontests/views/urls.py b/tests/regressiontests/views/urls.py index a86b0d4ccc..bd95dacd06 100644 --- a/tests/regressiontests/views/urls.py +++ b/tests/regressiontests/views/urls.py @@ -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 diff --git a/tests/regressiontests/views/views.py b/tests/regressiontests/views/views.py index 20ee56f985..f54de91c80 100644 --- a/tests/regressiontests/views/views.py +++ b/tests/regressiontests/views/views.py @@ -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('Dummy page') - 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.