#24338: {%extends%}-ing a file-based template object is broken by deprecation
path
indirection
---------------------------------+-----------------------
Reporter: spectras | Owner: nobody
Type: Uncategorized | Status: new
Component: Template system | Version: 1.8alpha1
Severity: Normal | Keywords: template
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------
Hello,
I could not find it on the bug tracker, sorry if I just missed it.
I am using git version, commit id bd80fa6b0f7e5a0cc4ea26cedd56d0c4c4894420
on branch stable/1.8.x
Setup:
* load a template in a view using select_template
* insert the result of select_template into the {{{context['foo']}}} of
another template, that has {{{{% extends foo %}}}}.
* render that template with that context.
That is:
{{{#!python
# as part of a class-based view
template_name = 'child_template.html'
def get(self, *args, **kwargs):
context = self.get_context_data()
context['base_template'] = select_template(['foo.html', 'bar.html'])
return self.render_to_response(context)
}}}
If child_template.html contains a '''{% extends base_template %}''', the
rendering process will break while trying to access the template's
nodelist:
{{{
======================================================================
ERROR: test_admin_change_form_title (hvad.tests.admin.NormalAdminTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/spectras/Projects/hvad/django-hvad/hvad/tests/admin.py",
line 226, in test_admin_change_form_title
response = self.client.get(url)
File "/home/spectras/Projects/hvad/django/django/test/client.py", line
499, in get
**extra)
File "/home/spectras/Projects/hvad/django/django/test/client.py", line
302, in get
return self.generic('GET', path, secure=secure, **r)
File "/home/spectras/Projects/hvad/django/django/test/client.py", line
378, in generic
return self.request(**r)
File "/home/spectras/Projects/hvad/django/django/test/client.py", line
465, in request
six.reraise(*exc_info)
File "/home/spectras/Projects/hvad/django/django/utils/six.py", line
659, in reraise
raise value
File "/home/spectras/Projects/hvad/django/django/core/handlers/base.py",
line 163, in get_response
response = response.render()
File "/home/spectras/Projects/hvad/django/django/template/response.py",
line 158, in render
self.content = self.rendered_content
File "/home/spectras/Projects/hvad/django/django/template/response.py",
line 135, in rendered_content
content = template.render(context, self._request)
File
"/home/spectras/Projects/hvad/django/django/template/backends/django.py",
line 83, in render
return self.template.render(context)
File "/home/spectras/Projects/hvad/django/django/template/base.py", line
211, in render
return self._render(context)
File "/home/spectras/Projects/hvad/django/django/test/utils.py", line
96, in instrumented_test_render
return self.nodelist.render(context)
File "/home/spectras/Projects/hvad/django/django/template/base.py", line
905, in render
bit = self.render_node(node, context)
File "/home/spectras/Projects/hvad/django/django/template/debug.py",
line 80, in render_node
return node.render(context)
File
"/home/spectras/Projects/hvad/django/django/template/loader_tags.py", line
118, in render
for node in compiled_parent.nodelist:
AttributeError: 'Template' object has no attribute 'nodelist'
}}}
It seems the ExtendsNode tries to access template.nodelist directly.
However, the Template object returned by select_template is a
django.template.backends.django.Template, that encapsulates the actual
template, so it can intercept render() and throw some deprecation
warnings.
I guess it just misses a nodelist property that would forward to the
actual template's nodelist.
I can build a proper example if absolutely needed, but it seemed simple
enough that it would not be necessary.
--
Ticket URL: <https://code.djangoproject.com/ticket/24338>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.6122e92ff7ca04ff2144c5a10a2ae3b6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.