Ticket #12083: patch_12083.diff

File patch_12083.diff, 2.4 KB (added by Maciej Wiśniowski, 15 years ago)

proposed patch

  • django/views/debug.py

     
    245245    "Create a technical 404 error response. The exception should be the Http404."
    246246    try:
    247247        tried = exception.args[0]['tried']
    248     except (IndexError, TypeError):
     248    except (IndexError, TypeError, KeyError):
    249249        tried = []
    250250    else:
    251251        if not tried:
  • tests/regressiontests/views/tests/debug.py

     
    1919        response = self.client.post('/views/raises/', data)
    2020        self.failUnless('file_data.txt' in response.content)
    2121        self.failIf('haha' in response.content)
     22
     23    def test_404(self):
     24        response = self.client.get('/views/raises404/')
     25        self.assertEquals(response.status_code, 404)
     26 No newline at end of file
  • tests/regressiontests/views/views.py

     
    22
    33from django.http import HttpResponse, HttpResponseRedirect
    44from django import forms
    5 from django.views.debug import technical_500_response
     5from django.views.debug import technical_500_response, technical_404_response
    66from django.views.generic.create_update import create_object
     7from django.core.urlresolvers import get_resolver
    78
    89from models import Article
    910
     
    3738    except Exception:
    3839        return technical_500_response(request, *sys.exc_info())
    3940
     41def raises404(request):
     42    resolver = get_resolver(None)
     43    try:
     44        resolver.resolve('')
     45    except Exception, e:
     46        return technical_404_response(request, e)
     47       
    4048def redirect(request):
    4149    """
    4250    Forces an HTTP redirect.
  • tests/regressiontests/views/urls.py

     
    9595
    9696# a view that raises an exception for the debug view
    9797urlpatterns += patterns('',
    98     (r'^raises/$', views.raises)
     98    (r'^raises/$', views.raises),
     99    (r'^raises404/$', views.raises404)
    99100)
Back to Top