diff --git a/django/views/debug.py b/django/views/debug.py index 490d4bb..b24ff43 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -256,6 +256,7 @@ class ExceptionReporter(object): 'sys_path' : sys.path, 'template_info': self.template_info, 'template_does_not_exist': self.template_does_not_exist, + 'traceback': self.exception_string(), 'loader_debug_info': self.loader_debug_info, }) # Check whether exception info is available @@ -375,6 +376,10 @@ class ExceptionReporter(object): return frames + def exception_string(self): + unicode_fixed = [smart_unicode(f, errors='replace') for f in self.format_exception()] + return "".join([f for f in unicode_fixed]) + def format_exception(self): """ Return the same data as from traceback.format_exception. @@ -431,6 +436,11 @@ def empty_urlconf(request): TECHNICAL_500_TEMPLATE = """ +{% if traceback %} + +{% endif %} diff --git a/tests/regressiontests/views/tests/debug.py b/tests/regressiontests/views/tests/debug.py index 1dbaff4..06a56e4 100644 --- a/tests/regressiontests/views/tests/debug.py +++ b/tests/regressiontests/views/tests/debug.py @@ -149,6 +149,19 @@ class ExceptionReporterTests(TestCase): self.assertIn('

Request information

', html) self.assertIn('

Request data not supplied

', html) + def test_raw_traceback(self): + "The raw traceback is provided in a comment." + try: + request = self.rf.get('/test_view/') + raise ValueError("---------->") + except ValueError: + exc_type, exc_value, tb = sys.exc_info() + reporter = ExceptionReporter(request, exc_type, exc_value, tb) + html = reporter.get_traceback_html() + self.assertIn('')) + self.assertIn('---------->', html) + class ExceptionReporterFilterTests(TestCase): """