You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A {{ [1, 2, 3] | random }} interpolation results in one value being picked and re-used, no matter how often that interpolation is run inside a loop:
$ cat test.py
from jinja2 import Template
template = Template('''{%- for i in range(10) -%}{{ ['foo', 'bar', 'baz', 'eggs', 'ham', 'spam'] | random }}{{ '' }}{%- endfor %}''')
print(template.render())
$ python3 test.py
baz baz baz baz baz baz baz baz baz baz
This started with 2.9 and is present in 2.9.6 still. 2.8.1 doesn't show this behaviour (downgrading with pip install -U Jinja2==2.8.1 results in a proper random series of choices).
When you make the list a variable, things work as expected as well, so {% set seq = [...] %} then {{ seq | random }} works fine, as well as passing in the sequence as a template variable on rendering.
The text was updated successfully, but these errors were encountered:
A
{{ [1, 2, 3] | random }}
interpolation results in one value being picked and re-used, no matter how often that interpolation is run inside a loop:This started with 2.9 and is present in 2.9.6 still. 2.8.1 doesn't show this behaviour (downgrading with pip install -U Jinja2==2.8.1 results in a proper random series of choices).
When you make the list a variable, things work as expected as well, so
{% set seq = [...] %}
then{{ seq | random }}
works fine, as well as passing in the sequence as a template variable on rendering.The text was updated successfully, but these errors were encountered: