Commit 50e46c01 authored by Karen Tracey's avatar Karen Tracey
Browse files

Fixed #11461: Ensured complete traceback is available on the debug page when...

Fixed #11461: Ensured complete traceback is available on the debug page when an exception is encountered during template rendering, even when running on Python 2.6 or higher. Thanks Glenn.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@12725 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 5a35619b
Loading
Loading
Loading
Loading
+1 −14
Original line number Diff line number Diff line
@@ -104,20 +104,7 @@ builtins = []
invalid_var_format_string = None

class TemplateSyntaxError(Exception):
    def __str__(self):
        try:
            import cStringIO as StringIO
        except ImportError:
            import StringIO
        output = StringIO.StringIO()
        output.write(Exception.__str__(self))
        # Check if we wrapped an exception and print that too.
        if hasattr(self, 'exc_info'):
            import traceback
            output.write('\n\nOriginal ')
            e = self.exc_info
            traceback.print_exception(e[0], e[1], e[2], 500, output)
        return output.getvalue()
    pass

class TemplateDoesNotExist(Exception):
    pass
+3 −2
Original line number Diff line number Diff line
@@ -76,10 +76,11 @@ class DebugNodeList(NodeList):
            raise
        except Exception, e:
            from sys import exc_info
            wrapped = TemplateSyntaxError(u'Caught an exception while rendering: %s' % force_unicode(e, errors='replace'))
            wrapped = TemplateSyntaxError(u'Caught %s while rendering: %s' %
                (e.__class__.__name__, force_unicode(e, errors='replace')))
            wrapped.source = node.source
            wrapped.exc_info = exc_info()
            raise wrapped
            raise wrapped, None, wrapped.exc_info[2]
        return result

class DebugVariableNode(VariableNode):
+1 −1
Original line number Diff line number Diff line
@@ -216,7 +216,7 @@ class Templates(unittest.TestCase):
        except TemplateSyntaxError, e:
            # Assert that we are getting the template syntax error and not the
            # string encoding error.
            self.assertEquals(e.args[0], "Caught an exception while rendering: Reverse for 'will_not_match' with arguments '()' and keyword arguments '{}' not found.")
            self.assertEquals(e.args[0], "Caught NoReverseMatch while rendering: Reverse for 'will_not_match' with arguments '()' and keyword arguments '{}' not found.")

        settings.SETTINGS_MODULE = old_settings_module
        settings.TEMPLATE_DEBUG = old_template_debug
+0 −0

Empty file added.

+10 −0
Original line number Diff line number Diff line
from django import template
 
from regressiontests.views import BrokenException

register = template.Library()

@register.simple_tag
def go_boom(arg):
    raise BrokenException(arg)
Loading