From 55f12f8709f0604df7e1817a4c114ead1fb9a311 Mon Sep 17 00:00:00 2001 From: Preston Timmons Date: Fri, 6 Mar 2015 09:53:25 -0600 Subject: Cleaned up the template debug implementation. This patch does three major things: * Merges the django.template.debug implementation into django.template.base. * Simplifies the debug implementation. The old implementation copied debug information to every token and node. The django_template_source attribute was set in multiple places, some quite hacky, like django.template.defaulttags.ForNode. Debug information is now annotated in two high-level places: * Template.compile_nodelist for errors during parsing * Node.render_annotated for errors during rendering These were chosen because they have access to the template and context as well as to all exceptions that happen during either the parse or render phase. * Moves the contextual line traceback information creation from django.views.debug into django.template.base.Template. The debug views now only deal with the presentation of the debug information. --- tests/template_tests/syntax_tests/test_basic.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/template_tests/syntax_tests/test_basic.py') diff --git a/tests/template_tests/syntax_tests/test_basic.py b/tests/template_tests/syntax_tests/test_basic.py index 741b3ace8f..b72d6e6414 100644 --- a/tests/template_tests/syntax_tests/test_basic.py +++ b/tests/template_tests/syntax_tests/test_basic.py @@ -311,3 +311,15 @@ class BasicSyntaxTests(SimpleTestCase): """ output = self.engine.render_to_string('basic-syntax38', {"var": {"callable": lambda: "foo bar"}}) self.assertEqual(output, 'foo bar') + + @setup({'template': '{% block content %}'}) + def test_unclosed_block(self): + msg = "Unclosed tag 'block'. Looking for one of: endblock." + with self.assertRaisesMessage(TemplateSyntaxError, msg): + self.engine.render_to_string('template') + + @setup({'template': '{% if a %}'}) + def test_unclosed_block2(self): + msg = "Unclosed tag 'if'. Looking for one of: elif, else, endif." + with self.assertRaisesMessage(TemplateSyntaxError, msg): + self.engine.render_to_string('template') -- cgit v1.3