I'm using the excellent (Python) Flask framework (using the jinja2 templating engine) to build a website and in a template I now want to loop over a list to see if at least one of the items has an attribute which is set to a positive number. If so I need to show some other stuff, so I want to set a variable. I try to do this like so:
{% set showBag = False %}
{% for parcel in parcels %}
{{ parcel.bag }}
{% if parcel.bag %}
<br> Set showBag to True <br>
{% set showBag = True %}
{% endif%}
{% endfor %}
<br>
{{ showBag }}
which shows the following
3212
Set showBag to True
False
So as you can see parcel.bag is a positive number for at least one of the items, but still the showBag variable is False. The if seems to work but the variable isn't reset to True.
Could anybody be so kind to point me in the right direction? All tips are welcome!
Aucun commentaire:
Enregistrer un commentaire