Ticket #16770: unwrap_templatesyntaxerror.diff
File unwrap_templatesyntaxerror.diff, 7.4 KB (added by , 13 years ago) |
---|
-
django/views/debug.py
223 223 'loader': loader_name, 224 224 'templates': template_list, 225 225 }) 226 if (settings.TEMPLATE_DEBUG and hasattr(self.exc_value, 'source') and 227 isinstance(self.exc_value, TemplateSyntaxError)): 226 if (settings.TEMPLATE_DEBUG and hasattr(self.exc_value, 'source_template_node')): 228 227 self.get_template_exception_info() 229 228 230 229 frames = self.get_traceback_frames() … … 268 267 return t.render(c) 269 268 270 269 def get_template_exception_info(self): 271 origin, (start, end) = self.exc_value.source 270 origin, (start, end) = self.exc_value.source_template_node 272 271 template_source = origin.reload() 273 272 context_lines = 10 274 273 line = 0 … … 626 625 {% endif %} 627 626 {% if template_info %} 628 627 <div id="template"> 629 <h2> Template error</h2>628 <h2>Error occured during template rendering</h2> 630 629 <p>In template <code>{{ template_info.name }}</code>, error at line <strong>{{ template_info.line }}</strong></p> 631 630 <h3>{{ template_info.message }}</h3> 632 631 <table class="source{% if template_info.top %} cut-top{% endif %}{% ifnotequal template_info.bottom template_info.total %} cut-bottom{% endifnotequal %}"> -
django/template/debug.py
4 4 from django.utils.safestring import SafeData, EscapeData 5 5 from django.utils.formats import localize 6 6 7 7 8 class DebugLexer(Lexer): 8 9 def __init__(self, template_string, origin): 9 10 super(DebugLexer, self).__init__(template_string, origin) … … 42 43 def error(self, token, msg): 43 44 return self.source_error(token.source, msg) 44 45 45 def source_error(self, source, msg):46 def source_error(self, source, msg): 46 47 e = TemplateSyntaxError(msg) 47 e.source = source48 e.source_template_node = source #Identify the template node that was being rendered when the error occurred. 48 49 return e 49 50 50 51 def create_nodelist(self): … … 67 68 e.source = token.source 68 69 69 70 class DebugNodeList(NodeList): 71 ''' 72 A list of nodes that is instantiated when debug is True - this is the nerve center of exceptions that occur during template rendering. 73 ''' 70 74 def render_node(self, node, context): 71 75 try: 72 76 result = node.render(context) 73 77 except TemplateSyntaxError, e: 74 if not hasattr(e, 'source '):75 e.source = node.source76 raise 78 if not hasattr(e, 'source_template_node'): #Have we already identified the node where the problem occured? 79 e.source_template_node = node.source #...if so, let's annotate the exception with that. 80 raise 77 81 except Exception, e: 78 82 from sys import exc_info 79 wrapped = TemplateSyntaxError(u'Caught %s while rendering: %s' % 80 (e.__class__.__name__, force_unicode(e, errors='replace'))) 81 wrapped.source = getattr(e, 'template_node_source', node.source) 82 wrapped.exc_info = exc_info() 83 raise wrapped, None, wrapped.exc_info[2] 83 e.source_template_node = getattr(e, 'template_node_source', node.source) #Again, annotating the exception with the node 84 e.exc_info = exc_info() 85 raise e, None, e.exc_info[2] #Make sure that ExceptionReporter gets the traceback 84 86 return result 85 87 86 88 class DebugVariableNode(VariableNode): -
django/views/debug.py
223 223 'loader': loader_name, 224 224 'templates': template_list, 225 225 }) 226 if (settings.TEMPLATE_DEBUG and hasattr(self.exc_value, 'source') and 227 isinstance(self.exc_value, TemplateSyntaxError)): 226 if (settings.TEMPLATE_DEBUG and hasattr(self.exc_value, 'source_template_node')): 228 227 self.get_template_exception_info() 229 228 230 229 frames = self.get_traceback_frames() … … 268 267 return t.render(c) 269 268 270 269 def get_template_exception_info(self): 271 origin, (start, end) = self.exc_value.source 270 origin, (start, end) = self.exc_value.source_template_node 272 271 template_source = origin.reload() 273 272 context_lines = 10 274 273 line = 0 … … 626 625 {% endif %} 627 626 {% if template_info %} 628 627 <div id="template"> 629 <h2> Template error</h2>628 <h2>Error occured during template rendering</h2> 630 629 <p>In template <code>{{ template_info.name }}</code>, error at line <strong>{{ template_info.line }}</strong></p> 631 630 <h3>{{ template_info.message }}</h3> 632 631 <table class="source{% if template_info.top %} cut-top{% endif %}{% ifnotequal template_info.bottom template_info.total %} cut-bottom{% endifnotequal %}"> -
django/template/debug.py
4 4 from django.utils.safestring import SafeData, EscapeData 5 5 from django.utils.formats import localize 6 6 7 7 8 class DebugLexer(Lexer): 8 9 def __init__(self, template_string, origin): 9 10 super(DebugLexer, self).__init__(template_string, origin) … … 42 43 def error(self, token, msg): 43 44 return self.source_error(token.source, msg) 44 45 45 def source_error(self, source, msg):46 def source_error(self, source, msg): 46 47 e = TemplateSyntaxError(msg) 47 e.source = source48 e.source_template_node = source #Identify the template node that was being rendered when the error occurred. 48 49 return e 49 50 50 51 def create_nodelist(self): … … 67 68 e.source = token.source 68 69 69 70 class DebugNodeList(NodeList): 71 ''' 72 A list of nodes that is instantiated when debug is True - this is the nerve center of exceptions that occur during template rendering. 73 ''' 70 74 def render_node(self, node, context): 71 75 try: 72 76 result = node.render(context) 73 77 except TemplateSyntaxError, e: 74 if not hasattr(e, 'source '):75 e.source = node.source76 raise 78 if not hasattr(e, 'source_template_node'): #Have we already identified the node where the problem occured? 79 e.source_template_node = node.source #...if so, let's annotate the exception with that. 80 raise 77 81 except Exception, e: 78 82 from sys import exc_info 79 wrapped = TemplateSyntaxError(u'Caught %s while rendering: %s' % 80 (e.__class__.__name__, force_unicode(e, errors='replace'))) 81 wrapped.source = getattr(e, 'template_node_source', node.source) 82 wrapped.exc_info = exc_info() 83 raise wrapped, None, wrapped.exc_info[2] 83 e.source_template_node = getattr(e, 'template_node_source', node.source) #Again, annotating the exception with the node 84 e.exc_info = exc_info() 85 raise e, None, e.exc_info[2] #Make sure that ExceptionReporter gets the traceback 84 86 return result 85 87 86 88 class DebugVariableNode(VariableNode):