1
0
mirror of https://github.com/django/django.git synced 2025-10-28 08:06:09 +00:00

[1.8.x] Fixed #24338 -- Accepted Template wrapper in {% extends %}.

Explicitly checking for django.template.Template subclasses is
preferrable to duck-typing because both the django.template.Template and
django.template.backends.django.Template have a render() method.

Thanks spectras for the report.

Backport of 47ee7b48 from master
This commit is contained in:
Aymeric Augustin
2015-02-14 10:21:06 +01:00
parent 20b621eb3c
commit 0f3eb8260b
2 changed files with 19 additions and 4 deletions

View File

@@ -1,7 +1,8 @@
from collections import defaultdict
from django.template.base import (
Library, Node, TemplateSyntaxError, TextNode, Variable, token_kwargs,
Library, Node, Template, TemplateSyntaxError, TextNode, Variable,
token_kwargs,
)
from django.utils import six
from django.utils.safestring import mark_safe
@@ -100,8 +101,12 @@ class ExtendsNode(Node):
error_msg += " Got this from the '%s' variable." %\
self.parent_name.token
raise TemplateSyntaxError(error_msg)
if hasattr(parent, 'render'):
return parent # parent is a Template object
if isinstance(parent, Template):
# parent is a django.template.Template
return parent
if isinstance(getattr(parent, 'template', None), Template):
# parent is a django.template.backends.django.Template
return parent.template
return context.engine.get_template(parent)
def render(self, context):