mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Improved {% include %} implementation
Merged BaseIncludeNode, ConstantIncludeNode and Include node. This avoids raising TemplateDoesNotExist at parsing time, allows recursion when passing a literal template name, and should make TEMPLATE_DEBUG behavior consistant. Thanks loic84 for help with the tests. Fixed #3544, fixed #12064, fixed #16147
This commit is contained in:
parent
e973ee6a98
commit
e2f06226ea
4 changed files with 56 additions and 38 deletions
|
@ -349,6 +349,40 @@ class TemplateLoaderTests(TestCase):
|
|||
output = outer_tmpl.render(ctx)
|
||||
self.assertEqual(output, 'This worked!')
|
||||
|
||||
@override_settings(TEMPLATE_DEBUG=True)
|
||||
def test_include_immediate_missing(self):
|
||||
"""
|
||||
Regression test for #16417 -- {% include %} tag raises TemplateDoesNotExist at compile time if TEMPLATE_DEBUG is True
|
||||
|
||||
Test that an {% include %} tag with a literal string referencing a
|
||||
template that does not exist does not raise an exception at parse
|
||||
time.
|
||||
"""
|
||||
ctx = Context()
|
||||
tmpl = Template('{% include "this_does_not_exist.html" %}')
|
||||
self.assertIsInstance(tmpl, Template)
|
||||
|
||||
@override_settings(TEMPLATE_DEBUG=True)
|
||||
def test_include_recursive(self):
|
||||
comments = [
|
||||
{
|
||||
'comment': 'A1',
|
||||
'children': [
|
||||
{'comment': 'B1', 'children': []},
|
||||
{'comment': 'B2', 'children': []},
|
||||
{'comment': 'B3', 'children': [
|
||||
{'comment': 'C1', 'children': []}
|
||||
]},
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
t = loader.get_template('recursive_include.html')
|
||||
self.assertEqual(
|
||||
"Recursion! A1 Recursion! B1 B2 B3 Recursion! C1",
|
||||
t.render(Context({'comments': comments})).replace(' ', '').replace('\n', ' ').strip(),
|
||||
)
|
||||
|
||||
|
||||
class TemplateRegressionTests(TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue