Solution 1 :

Jinja doesn’t actually have a zip global function. So you need to make it available by doing:

app.jinja_env.globals.update(zip=zip)

Additionally, assignments require using the set keyword, e.g. {% set a = i + j %}

{% for i, j in items %}
    {% set a = i + j %}

{% endfor %}

See also: zip(list1, list2) in Jinja2?”

Solution 2 :

Thank you , it was very helpful. I just did this and worked:
in init.py file I add this:

app.jinja_env.filters['zip'] = zip

in the index.html:

{% for i, j in items | zip(teams) %}
 {% set a = i + j %}
{% endfor %}

Problem :

I am developing a web using flask. I have two class objects from models.py. I need to loop over both of them at the same time in my HTML file using Jinja2.

For example:
I want to have the following code in jinja2 format:

for i,j in zip(items, team):
    a= i+j

Want to convert it to jinja2 format:

{% for i,j  in zip(items, teams) %}
    {% a=i+j %}
{% endfor%}

What is the problem with this jinja2 code?

Comments

Comment posted by stackoverflow.com/help/how-to-ask

Please refer to this :

Comment posted by Jasper

Thank you , it was very helpful. I just did this and worked: in

By