mitsuhiko/jinja2 — Issue #86: Nested For Loop with Else Causes Exception
Author: mankyd
Created: 2012-01-11 14:06:21+00:00
State: open

Create a for loop with an else clause. In the main clause of the for loop, access {{ loop.index }}. In the else clause, put another for loop. When you render the template, you get an exception:

>>> env = jinja2.Environment()
>>> tpl = env.from_string('{% for x in y %}{{ loop.index0 }}{% else %}{% for i in range(3) %}{{ i }}{% endfor %}{% endfor %}')
>>> tpl.render(y=[])
Traceback (most recent call last):
File "", line 1, in
File "/Users/dave/om/trunk/lib/python2.7/site-packages/Jinja2-2.6-py2.7.egg/jinja2/environment.py", line 894, in render
return self.environment.handle_exception(exc_info, True)
File "