Answer the question
In order to leave comments, you need to log in
How to get out of a loop in jinja2?
Hello. Tell me how to exit the loop in jinja2. The description of the task is as follows:
A response is received from an Ajax request, the response (object) contains a property whose value is an array. I want to display the elements of this array, but there is one condition, the array elements can contain the same values, in which case I need to display only the first element. With the current implementation, if all elements are the same, then they are not displayed at all.
{% for tariff_tag in data.sub_tariff if not tariff_tag.tariff__tariff_category == 'amedia-subscription' %}
<a>link</a>
{% endfor %}
Answer the question
In order to leave comments, you need to log in
Thank you all for your comments. The actual solution was to simply extend jinja with the loopcontrols module
app.jinja_env.add_extension('jinja2.ext.loopcontrols')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question