Ticket #16227: traceback-in-comment.patch

File traceback-in-comment.patch, 2.2 KB (added by Daniel Watkins, 8 years ago)
  • django/views/debug.py

    diff --git a/django/views/debug.py b/django/views/debug.py
    index 490d4bb..b24ff43 100644
    a b class ExceptionReporter(object): 
    256256            'sys_path' : sys.path,
    257257            'template_info': self.template_info,
    258258            'template_does_not_exist': self.template_does_not_exist,
     259            'traceback': self.exception_string(),
    259260            'loader_debug_info': self.loader_debug_info,
    260261        })
    261262        # Check whether exception info is available
    class ExceptionReporter(object): 
    375376
    376377        return frames
    377378
     379    def exception_string(self):
     380        unicode_fixed = [smart_unicode(f, errors='replace') for f in self.format_exception()]
     381        return "".join([f for f in unicode_fixed])
     382
    378383    def format_exception(self):
    379384        """
    380385        Return the same data as from traceback.format_exception.
    def empty_urlconf(request): 
    431436TECHNICAL_500_TEMPLATE = """
    432437<!DOCTYPE html>
    433438<html lang="en">
     439{% if traceback %}
     440<!----------
     441{{ traceback }}
     442---------->
     443{% endif %}
    434444<head>
    435445  <meta http-equiv="content-type" content="text/html; charset=utf-8">
    436446  <meta name="robots" content="NONE,NOARCHIVE">
  • tests/regressiontests/views/tests/debug.py

    diff --git a/tests/regressiontests/views/tests/debug.py b/tests/regressiontests/views/tests/debug.py
    index 1dbaff4..06a56e4 100644
    a b class ExceptionReporterTests(TestCase): 
    149149        self.assertIn('<h2>Request information</h2>', html)
    150150        self.assertIn('<p>Request data not supplied</p>', html)
    151151
     152    def test_raw_traceback(self):
     153        "The raw traceback is provided in a comment."
     154        try:
     155            request = self.rf.get('/test_view/')
     156            raise ValueError("---------->")
     157        except ValueError:
     158            exc_type, exc_value, tb = sys.exc_info()
     159        reporter = ExceptionReporter(request, exc_type, exc_value, tb)
     160        html = reporter.get_traceback_html()
     161        self.assertIn('<!----------', html)
     162        self.assertEquals(1, html.count('---------->'))
     163        self.assertIn('---------->', html)
     164
    152165
    153166class ExceptionReporterFilterTests(TestCase):
    154167    """
Back to Top