Syntax error in generated python with double {% extends %} #79

Closed
SimonSapin opened this Issue Dec 6, 2011 · 1 comment

Comments

Projects
None yet
2 participants
Contributor

SimonSapin commented Dec 6, 2011

Using more than one {% extends %} is not allowed, but the error message and location could be more explicit:

>>> jinja2.Template('{% extends "a" %}{% extends "b" %}')
  File "<template>", line 13
SyntaxError: 'yield' outside function (<template>, line 13)
Contributor

paradoxxxzero commented Jan 5, 2012

This is due to this code being generated:

def root(context, environment=environment):
    parent_template = None
    if 0: yield None
    if parent_template is None:
        yield u'Before include\n'
    parent_template = environment.get_template('i.jinja2', 'a')
    for name, parent_block in parent_template.blocks.iteritems():
        context.blocks.setdefault(name, []).append(parent_block)
    raise TemplateRuntimeError('extended multiple times')
for event in parent_template.root_render_func(context):
    yield event

blocks = {}
debug_info = '2=10'

@paradoxxxzero paradoxxxzero added a commit to paradoxxxzero/jinja2 that referenced this issue Jan 5, 2012

@paradoxxxzero paradoxxxzero Outdent only if raise has been indented in multiple inheritance error…
… handling. Fixes #79
4b2e99f

mitsuhiko closed this in 400f973 May 19, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment