diff --git a/django/template/base.py b/django/template/base.py index e23420b828..31bc8c924b 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -250,15 +250,15 @@ class Parser(object): var_node = self.create_variable_node(filter_expression) self.extend_nodelist(nodelist, var_node, token) elif token.token_type == TOKEN_BLOCK: - if token.contents in parse_until: - # put token back on token list so calling - # code knows why it terminated - self.prepend_token(token) - return nodelist try: command = token.contents.split()[0] except IndexError: self.empty_block_tag(token) + if command in parse_until: + # put token back on token list so calling + # code knows why it terminated + self.prepend_token(token) + return nodelist # execute callback function for this tag and append # resulting node self.enter_command(command, token) diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py index b642765341..521df2dd8d 100644 --- a/django/template/loader_tags.py +++ b/django/template/loader_tags.py @@ -189,8 +189,14 @@ def do_block(parser, token): parser.__loaded_blocks.append(block_name) except AttributeError: # parser.__loaded_blocks isn't a list yet parser.__loaded_blocks = [block_name] - nodelist = parser.parse(('endblock', 'endblock %s' % block_name)) - parser.delete_first_token() + nodelist = parser.parse(('endblock',)) + + # This check is kept for backwards-compatibility. See #3100. + endblock = parser.next_token() + acceptable_endblocks = ('endblock', 'endblock %s' % block_name) + if endblock.contents not in acceptable_endblocks: + parser.invalid_block_tag(endblock, 'endblock', acceptable_endblocks) + return BlockNode(block_name, nodelist) @register.tag('extends')