[1.11.x] Fixed #27722 -- Reallowed using django.Template in {% include %}.

Backport of fe2d288434 from master
This commit is contained in:
Tim Graham 2017-02-11 06:51:57 -05:00
parent eeb28f4751
commit 9658f0d266
3 changed files with 10 additions and 1 deletions

View File

@ -202,6 +202,9 @@ class IncludeNode(Node):
if template is None: if template is None:
template = context.template.engine.get_template(template_name) template = context.template.engine.get_template(template_name)
cache[template_name] = template cache[template_name] = template
# Use the base.Template of a backends.django.Template.
elif hasattr(template, 'template'):
template = template.template
values = { values = {
name: var.resolve(context) name: var.resolve(context)
for name, var in six.iteritems(self.extra_context) for name, var in six.iteritems(self.extra_context)

View File

@ -1,7 +1,7 @@
import warnings import warnings
from django.template import ( from django.template import (
Context, Engine, TemplateDoesNotExist, TemplateSyntaxError, Context, Engine, TemplateDoesNotExist, TemplateSyntaxError, loader,
) )
from django.test import SimpleTestCase, ignore_warnings from django.test import SimpleTestCase, ignore_warnings
from django.utils.deprecation import RemovedInDjango21Warning from django.utils.deprecation import RemovedInDjango21Warning
@ -280,6 +280,11 @@ class IncludeTests(SimpleTestCase):
output = outer_tmpl.render(ctx) output = outer_tmpl.render(ctx)
self.assertEqual(output, 'This worked!') self.assertEqual(output, 'This worked!')
def test_include_from_loader_get_template(self):
tmpl = loader.get_template('include_tpl.html') # {% include tmpl %}
output = tmpl.render({'tmpl': loader.get_template('index.html')})
self.assertEqual(output, 'index\n\n')
def test_include_immediate_missing(self): def test_include_immediate_missing(self):
""" """
#16417 -- Include tags pointing to missing templates should not raise #16417 -- Include tags pointing to missing templates should not raise

View File

@ -0,0 +1 @@
{% include tmpl %}