Ticket #17660: 17660.patch

File 17660.patch, 2.3 KB (added by FunkyBob, 3 years ago)
  • django/template/loader_tags.py

     
    7474class ExtendsNode(Node):
    7575    must_be_first = True
    7676
    77     def __init__(self, nodelist, parent_name, parent_name_expr, template_dirs=None):
     77    def __init__(self, nodelist, parent_name, template_dirs=None):
    7878        self.nodelist = nodelist
    79         self.parent_name, self.parent_name_expr = parent_name, parent_name_expr
     79        self.parent_name = parent_name
    8080        self.template_dirs = template_dirs
    8181        self.blocks = dict([(n.name, n) for n in nodelist.get_nodes_by_type(BlockNode)])
    8282
    8383    def __repr__(self):
    84         if self.parent_name_expr:
    85             return "<ExtendsNode: extends %s>" % self.parent_name_expr.token
    8684        return '<ExtendsNode: extends "%s">' % self.parent_name
    8785
    8886    def get_parent(self, context):
    89         if self.parent_name_expr:
    90             parent = self.parent_name_expr.resolve(context)
    91         else:
    92             parent = self.parent_name
     87        parent = self.parent_name.resolve(context)
    9388        if not parent:
    9489            error_msg = "Invalid template name in 'extends' tag: %r." % parent
    95             if self.parent_name_expr:
    96                 error_msg += " Got this from the '%s' variable." % self.parent_name_expr.token
    9790            raise TemplateSyntaxError(error_msg)
    9891        if hasattr(parent, 'render'):
    9992            return parent # parent is a Template object
     
    212205    bits = token.split_contents()
    213206    if len(bits) != 2:
    214207        raise TemplateSyntaxError("'%s' takes one argument" % bits[0])
    215     parent_name, parent_name_expr = None, None
    216     if bits[1][0] in ('"', "'") and bits[1][-1] == bits[1][0]:
    217         parent_name = bits[1][1:-1]
    218     else:
    219         parent_name_expr = parser.compile_filter(bits[1])
     208    parent_name = parser.compile_filter(bits[1])
    220209    nodelist = parser.parse()
    221210    if nodelist.get_nodes_by_type(ExtendsNode):
    222211        raise TemplateSyntaxError("'%s' cannot appear more than once in the same template" % bits[0])
    223     return ExtendsNode(nodelist, parent_name, parent_name_expr)
     212    return ExtendsNode(nodelist, parent_name)
    224213
    225214@register.tag('include')
    226215def do_include(parser, token):
Back to Top