1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #27974 -- Kept resolved templates constant during one rendering cycle.

Thanks Florian Apolloner for the initial patch.
This commit is contained in:
kapil garg
2017-04-04 07:59:39 +05:30
committed by Tim Graham
parent ef8a339dfb
commit 002fe07622
4 changed files with 47 additions and 1 deletions

View File

@@ -308,3 +308,23 @@ class IncludeTests(SimpleTestCase):
"Recursion! A1 Recursion! B1 B2 B3 Recursion! C1",
t.render(Context({'comments': comments})).replace(' ', '').replace('\n', ' ').strip(),
)
def test_include_cache(self):
"""
{% include %} keeps resolved templates constant (#27974). The
CounterNode object in the {% counter %} template tag is created once
if caching works properly. Each iteration increases the counter instead
of restarting it.
This works as a regression test only if the cached loader
isn't used, so the @setup decorator isn't used.
"""
engine = Engine(loaders=[
('django.template.loaders.locmem.Loader', {
'template': '{% for x in vars %}{% include "include" %}{% endfor %}',
'include': '{% include "next" %}',
'next': '{% load custom %}{% counter %}'
}),
], libraries={'custom': 'template_tests.templatetags.custom'})
output = engine.render_to_string('template', dict(vars=range(9)))
self.assertEqual(output, '012345678')