Neil
Neil

Reputation: 17

Looping through the length of a list in jinja2

I'm looking to populate something similar in jinja in html.

for i in range(len(my_list)):

  for j in my_list:

    print(i,j)

I need both the i, j value as well and to not just iterate through the list.

Don't know if there is something equivalent to range in jinja2

Upvotes: 1

Views: 946

Answers (1)

blhsing
blhsing

Reputation: 106792

You can use loop.index0 for the purpose:

{% for i in my_list %}
  {{loop.index0}} {{i}}
{% endfor %}

Upvotes: 1

Related Questions