diff options
author | Tim Heap <tim@timheap.me> | 2015-03-31 15:37:17 +1100 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2015-04-01 12:26:57 -0400 |
commit | 4ea1909d3c420ba1fbdbf7221cad518d43aef885 (patch) | |
tree | 0415d0bb11470c5fe4681129662caf484362a1c8 /tests/template_backends | |
parent | 48ddc66219deaac2aa5fa3d2cb0f420404d6b8ec (diff) | |
download | django-4ea1909d3c420ba1fbdbf7221cad518d43aef885.tar.gz |
Fixed #24538 -- Allowed self in Jinja context
Rendering a Jinja template with self in the context threw an error.
While self is a reserved variable in Jinja, including self in the
context is not an error, so Django should respect that.
Diffstat (limited to 'tests/template_backends')
-rw-r--r-- | tests/template_backends/test_jinja2.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/template_backends/test_jinja2.py b/tests/template_backends/test_jinja2.py index 5f69669446..4c22c0958b 100644 --- a/tests/template_backends/test_jinja2.py +++ b/tests/template_backends/test_jinja2.py @@ -21,3 +21,21 @@ class Jinja2Tests(TemplateStringsTests): engine_class = Jinja2 backend_name = 'jinja2' options = {'keep_trailing_newline': True} + + def test_self_context(self): + """ + #24538 -- Using 'self' in the context should not throw errors + """ + engine = Jinja2({ + 'DIRS': [], + 'APP_DIRS': False, + 'NAME': 'django', + 'OPTIONS': {}, + }) + + # self will be overridden to be a TemplateReference, so the self + # variable will not come through. Attempting to use one though should + # not throw an error. + template = engine.from_string('hello {{ foo }}!') + content = template.render(context={'self': 'self', 'foo': 'world'}) + self.assertEqual(content, 'hello world!') |