Loading django/views/debug.py +3 −3 Original line number Diff line number Diff line Loading @@ -227,7 +227,7 @@ class ExceptionReporter(object): return "File exists" def get_traceback_data(self): "Return a Context instance containing traceback information." """Return a dictionary containing traceback information.""" if self.exc_type and issubclass(self.exc_type, TemplateDoesNotExist): from django.template.loader import template_source_loaders Loading Loading @@ -295,13 +295,13 @@ class ExceptionReporter(object): def get_traceback_html(self): "Return HTML version of debug 500 HTTP error page." t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template') c = Context(self.get_traceback_data()) c = Context(self.get_traceback_data(), use_l10n=False) return t.render(c) def get_traceback_text(self): "Return plain text version of debug 500 HTTP error page." t = Template(TECHNICAL_500_TEXT_TEMPLATE, name='Technical 500 template') c = Context(self.get_traceback_data(), autoescape=False) c = Context(self.get_traceback_data(), autoescape=False, use_l10n=False) return t.render(c) def get_template_exception_info(self): Loading tests/view_tests/tests/test_debug.py +16 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ from __future__ import unicode_literals import inspect import os import re import shutil import sys from tempfile import NamedTemporaryFile, mkdtemp, mkstemp Loading Loading @@ -69,6 +70,21 @@ class DebugViewTests(TestCase): self.assertRaises(BrokenException, self.client.get, reverse('view_exception', args=(n,))) def test_non_l10ned_numeric_ids(self): """ Numeric IDs and fancy traceback context blocks line numbers shouldn't be localized. """ with self.settings(DEBUG=True, USE_L10N=True): response = self.client.get('/views/raises500/') # We look for a HTML fragment of the form # '<div class="context" id="c38123208">', not '<div class="context" id="c38,123,208"' self.assertContains(response, '<div class="context" id="', status_code=500) match = re.search(b'<div class="context" id="(?P<id>[^"]+)">', response.content) self.assertFalse(match is None) id_repr = match.group('id') self.assertFalse(re.search(b'[^c\d]', id_repr), "Numeric IDs in debug response HTML page shouldn't be localized (value: %s)." % id_repr) def test_template_exceptions(self): for n in range(len(except_args)): try: Loading tests/view_tests/urls.py +1 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ urlpatterns = patterns('', (r'raises400/$', views.raises400), (r'raises403/$', views.raises403), (r'raises404/$', views.raises404), (r'raises500/$', views.raises500), # i18n views (r'^i18n/', include('django.conf.urls.i18n')), Loading tests/view_tests/views.py +8 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,14 @@ def raises(request): except Exception: return technical_500_response(request, *sys.exc_info()) def raises500(request): # We need to inspect the HTML generated by the fancy 500 debug view but # the test client ignores it, so we send it explicitly. try: raise Exception except Exception: return technical_500_response(request, *sys.exc_info()) def raises400(request): raise SuspiciousOperation Loading Loading
django/views/debug.py +3 −3 Original line number Diff line number Diff line Loading @@ -227,7 +227,7 @@ class ExceptionReporter(object): return "File exists" def get_traceback_data(self): "Return a Context instance containing traceback information." """Return a dictionary containing traceback information.""" if self.exc_type and issubclass(self.exc_type, TemplateDoesNotExist): from django.template.loader import template_source_loaders Loading Loading @@ -295,13 +295,13 @@ class ExceptionReporter(object): def get_traceback_html(self): "Return HTML version of debug 500 HTTP error page." t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template') c = Context(self.get_traceback_data()) c = Context(self.get_traceback_data(), use_l10n=False) return t.render(c) def get_traceback_text(self): "Return plain text version of debug 500 HTTP error page." t = Template(TECHNICAL_500_TEXT_TEMPLATE, name='Technical 500 template') c = Context(self.get_traceback_data(), autoescape=False) c = Context(self.get_traceback_data(), autoescape=False, use_l10n=False) return t.render(c) def get_template_exception_info(self): Loading
tests/view_tests/tests/test_debug.py +16 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ from __future__ import unicode_literals import inspect import os import re import shutil import sys from tempfile import NamedTemporaryFile, mkdtemp, mkstemp Loading Loading @@ -69,6 +70,21 @@ class DebugViewTests(TestCase): self.assertRaises(BrokenException, self.client.get, reverse('view_exception', args=(n,))) def test_non_l10ned_numeric_ids(self): """ Numeric IDs and fancy traceback context blocks line numbers shouldn't be localized. """ with self.settings(DEBUG=True, USE_L10N=True): response = self.client.get('/views/raises500/') # We look for a HTML fragment of the form # '<div class="context" id="c38123208">', not '<div class="context" id="c38,123,208"' self.assertContains(response, '<div class="context" id="', status_code=500) match = re.search(b'<div class="context" id="(?P<id>[^"]+)">', response.content) self.assertFalse(match is None) id_repr = match.group('id') self.assertFalse(re.search(b'[^c\d]', id_repr), "Numeric IDs in debug response HTML page shouldn't be localized (value: %s)." % id_repr) def test_template_exceptions(self): for n in range(len(except_args)): try: Loading
tests/view_tests/urls.py +1 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ urlpatterns = patterns('', (r'raises400/$', views.raises400), (r'raises403/$', views.raises403), (r'raises404/$', views.raises404), (r'raises500/$', views.raises500), # i18n views (r'^i18n/', include('django.conf.urls.i18n')), Loading
tests/view_tests/views.py +8 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,14 @@ def raises(request): except Exception: return technical_500_response(request, *sys.exc_info()) def raises500(request): # We need to inspect the HTML generated by the fancy 500 debug view but # the test client ignores it, so we send it explicitly. try: raise Exception except Exception: return technical_500_response(request, *sys.exc_info()) def raises400(request): raise SuspiciousOperation Loading