Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #5124 -- Added a reasonable error when "extends" is not the fir…

…st template tag. Patch from k0001.

Refs #6274.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7084 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b9e088ae14141ccb6a5aaf7952868a6e15e1a6c7 1 parent 12ed189
@malcolmt malcolmt authored
Showing with 14 additions and 0 deletions.
  1. +7 −0 django/template/__init__.py
  2. +7 −0 django/template/loader_tags.py
View
7 django/template/__init__.py
@@ -289,6 +289,9 @@ def create_nodelist(self):
return NodeList()
def extend_nodelist(self, nodelist, node, token):
+ if (node.must_be_first and nodelist and
+ (not isinstance(nodelist[0], TextNode) or len(nodelist) > 2)):
+ raise TemplateSyntaxError("%r must be the first tag in the template." % node)
nodelist.append(node)
def enter_command(self, command, token):
@@ -708,6 +711,10 @@ def _resolve_lookup(self, context):
return current
class Node(object):
+ # Set this to True for nodes that must be first in the template (although
+ # they can be preceded by text nodes.
+ must_be_first = False
+
def render(self, context):
"Return the node rendered as a string"
pass
View
7 django/template/loader_tags.py
@@ -37,11 +37,18 @@ def add_parent(self, nodelist):
self.parent = BlockNode(self.name, nodelist)
class ExtendsNode(Node):
+ must_be_first = True
+
def __init__(self, nodelist, parent_name, parent_name_expr, template_dirs=None):
self.nodelist = nodelist
self.parent_name, self.parent_name_expr = parent_name, parent_name_expr
self.template_dirs = template_dirs
+ def __repr__(self):
+ if self.parent_name_expr:
+ return "<ExtendsNode: extends %s>" % self.parent_name_expr.token
+ return '<ExtendsNode: extends "%s">' % self.parent_name
+
def get_parent(self, context):
if self.parent_name_expr:
self.parent_name = self.parent_name_expr.resolve(context)

0 comments on commit b9e088a

Please sign in to comment.
Something went wrong with that request. Please try again.