diff options
| author | John D'Ambrosio <jdzero@users.noreply.github.com> | 2017-03-22 12:06:01 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-06-13 12:50:54 -0400 |
| commit | be68c0bf637d9b28780753575b889946a734ca0e (patch) | |
| tree | 29c81b9053cc673271f44086aab131160859f85e | |
| parent | 08bda82c237b9ad071538c2386b8bfc62fef7f7f (diff) | |
Fixed #28071 -- Fixed {% extends %} origin history.
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | django/template/loader_tags.py | 2 | ||||
| -rw-r--r-- | tests/template_tests/test_extends.py | 21 |
3 files changed, 23 insertions, 1 deletions
@@ -390,6 +390,7 @@ answer newbie questions, and generally made Django that much better: Johann Queuniet <johann.queuniet@adh.naellia.eu> john@calixto.net John D'Agostino <john.dagostino@gmail.com> + John D'Ambrosio <dambrosioj@gmail.com> John Huddleston <huddlej@wwu.edu> John Moses <moses.john.r@gmail.com> John Paulett <john@paulett.org> diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py index 69e7ce471d..6cc8dfc8e3 100644 --- a/django/template/loader_tags.py +++ b/django/template/loader_tags.py @@ -103,7 +103,7 @@ class ExtendsNode(Node): without extending the same template twice. """ history = context.render_context.setdefault( - self.context_key, [context.template.origin], + self.context_key, [self.origin], ) template, origin = context.template.engine.find_template( template_name, skip=history, diff --git a/tests/template_tests/test_extends.py b/tests/template_tests/test_extends.py index 270160a82a..0950340f52 100644 --- a/tests/template_tests/test_extends.py +++ b/tests/template_tests/test_extends.py @@ -117,3 +117,24 @@ class ExtendsBehaviorTests(SimpleTestCase): template = engine.get_template('base.html') output = template.render(Context({})) self.assertEqual(output.strip(), 'loader2 loader1') + + def test_block_override_in_extended_included_template(self): + """ + ExtendsNode.find_template() initializes history with self.origin + (#28071). + """ + engine = Engine( + loaders=[ + ['django.template.loaders.locmem.Loader', { + 'base.html': "{% extends 'base.html' %}{% block base %}{{ block.super }}2{% endblock %}", + 'included.html': + "{% extends 'included.html' %}{% block included %}{{ block.super }}B{% endblock %}", + }], + ['django.template.loaders.locmem.Loader', { + 'base.html': "{% block base %}1{% endblock %}{% include 'included.html' %}", + 'included.html': "{% block included %}A{% endblock %}", + }], + ], + ) + template = engine.get_template('base.html') + self.assertEqual(template.render(Context({})), '12AB') |
