Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Allow whitespace prior to an "extends" tag. This allows a little more…

… formatting flexibility. Refs #6274.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 10015fae4de33dd5dfd38a3a14a9ddd4cb8442bf 1 parent 6674718
@malcolmt malcolmt authored
Showing with 10 additions and 3 deletions.
  1. +10 −3 django/template/
13 django/template/
@@ -1,5 +1,5 @@
from django.template import TemplateSyntaxError, TemplateDoesNotExist, Variable
-from django.template import Library, Node
+from django.template import Library, Node, TextNode
from django.template.loader import get_template, get_template_from_string, find_template_source
from django.conf import settings
from django.utils.safestring import mark_safe
@@ -62,7 +62,14 @@ def get_parent(self, context):
def render(self, context):
compiled_parent = self.get_parent(context)
- parent_is_child = isinstance(compiled_parent.nodelist[0], ExtendsNode)
+ if len(compiled_parent.nodelist) > 1:
+ n0, n1 = compiled_parent.nodelist[:2]
+ else:
+ n0, n1 = compiled_parent.nodelist[0], None
+ parent_is_child = (isinstance(n0, ExtendsNode) or
+ (isinstance(n0, TextNode) and isinstance(n1, ExtendsNode)))
+ if parent_is_child:
+ extend_node = int(not isinstance(n0, ExtendsNode))
parent_blocks = dict([(, n) for n in compiled_parent.nodelist.get_nodes_by_type(BlockNode)])
for block_node in self.nodelist.get_nodes_by_type(BlockNode):
# Check for a BlockNode with this node's name, and replace it if found.
@@ -74,7 +81,7 @@ def render(self, context):
# add this BlockNode to the parent's ExtendsNode nodelist, so
# it'll be checked when the parent node's render() is called.
if parent_is_child:
- compiled_parent.nodelist[0].nodelist.append(block_node)
+ compiled_parent.nodelist[extend_node].nodelist.append(block_node)
# Keep any existing parents and add a new one. Used by BlockNode.
parent_block.parent = block_node.parent

0 comments on commit 10015fa

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