summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/template/context.py8
-rw-r--r--django/template/loader_tags.py2
-rw-r--r--tests/regressiontests/templates/tests.py4
3 files changed, 13 insertions, 1 deletions
diff --git a/django/template/context.py b/django/template/context.py
index 1c8b7dacd9..bcfaa3bf9e 100644
--- a/django/template/context.py
+++ b/django/template/context.py
@@ -99,6 +99,14 @@ class Context(BaseContext):
self.dicts.append(other_dict)
return other_dict
+ def new(self, values=None):
+ """
+ Returns a new Context with the same 'autoescape' value etc, but with
+ only the values given in 'values' stored.
+ """
+ return self.__class__(dict_=values, autoescape=self.autoescape,
+ current_app=self.current_app, use_l10n=self.use_l10n)
+
class RenderContext(BaseContext):
"""
A stack container for storing Template state.
diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py
index 70096aafee..e289ef0d9e 100644
--- a/django/template/loader_tags.py
+++ b/django/template/loader_tags.py
@@ -136,7 +136,7 @@ class BaseIncludeNode(Node):
values = dict([(name, var.resolve(context)) for name, var
in self.extra_context.iteritems()])
if self.isolated_context:
- return template.render(Context(values))
+ return template.render(context.new(values))
context.update(values)
output = template.render(context)
context.pop()
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 46aedb3da6..cb831348ce 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -1031,6 +1031,10 @@ class Templates(unittest.TestCase):
'include11': ('{% include "basic-syntax03" only with second=2 %}', {'first': '1'}, (' --- 2', 'INVALID --- 2')),
'include12': ('{% include "basic-syntax03" with first=1 only %}', {'second': '2'}, ('1 --- ', '1 --- INVALID')),
+ # autoescape context
+ 'include13': ('{% autoescape off %}{% include "basic-syntax03" %}{% endautoescape %}', {'first': '&'}, ('& --- ', '& --- INVALID')),
+ 'include14': ('{% autoescape off %}{% include "basic-syntax03" with first=var1 only %}{% endautoescape %}', {'var1': '&'}, ('& --- ', '& --- INVALID')),
+
'include-error01': ('{% include "basic-syntax01" with %}', {}, template.TemplateSyntaxError),
'include-error02': ('{% include "basic-syntax01" with "no key" %}', {}, template.TemplateSyntaxError),
'include-error03': ('{% include "basic-syntax01" with dotted.arg="error" %}', {}, template.TemplateSyntaxError),