diff options
| author | ekinertac <ekinertac@gmail.com> | 2024-10-06 15:29:35 +0300 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-10-10 12:21:02 +0200 |
| commit | 68cee15a8fd65bd6ee2329d80331f87cadd97ff5 (patch) | |
| tree | 7c2280cb78d4cbe61e8426f95c2f5116d4aee724 /tests/template_tests | |
| parent | e970bb7ca71c00594b42a024a15a8ac007cc2c7a (diff) | |
Fixed #35789 -- Improved the error message raised when the tag must be first in the template.
Diffstat (limited to 'tests/template_tests')
| -rw-r--r-- | tests/template_tests/test_extends.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/template_tests/test_extends.py b/tests/template_tests/test_extends.py index ce1838654b..0d2a93468c 100644 --- a/tests/template_tests/test_extends.py +++ b/tests/template_tests/test_extends.py @@ -1,9 +1,9 @@ import os -from django.template import Context, Engine, TemplateDoesNotExist +from django.template import Context, Engine, TemplateDoesNotExist, TemplateSyntaxError from django.test import SimpleTestCase -from .utils import ROOT +from .utils import ROOT, setup RECURSIVE = os.path.join(ROOT, "recursive_templates") @@ -181,3 +181,17 @@ class ExtendsBehaviorTests(SimpleTestCase): ) template = engine.get_template("base.html") self.assertEqual(template.render(Context({})), "12AB") + + @setup( + {"index.html": "{% block content %}B{% endblock %}{% extends 'base.html' %}"} + ) + def test_extends_not_first_tag_in_extended_template(self): + msg = "{% extends 'base.html' %} must be the first tag in 'index.html'." + with self.assertRaisesMessage(TemplateSyntaxError, msg): + self.engine.get_template("index.html") + + def test_extends_not_first_tag_in_extended_template_from_string(self): + template_string = "{% block content %}B{% endblock %}{% extends 'base.html' %}" + msg = "{% extends 'base.html' %} must be the first tag in the template." + with self.assertRaisesMessage(TemplateSyntaxError, msg): + Engine().from_string(template_string) |
