简体   繁体   中英

using “range” in a google app engine template for - loop

i've got an appengine project and in my template i want to do something like

{% for i in range(0, len(somelist)) %}
  {{ somelist[i] }} {{ otherlist[i] }}
{% endfor %}

i've tried using 'forloop.counter' to access list items too, but that didn't work out either. any suggestions?

regards, mux

What you might want to do instead is change the data that you're passing in to the template so that somelist and otherlist are zipped together into a single list:

combined_list = zip(somelist, otherlist)
...
{% for item in combined_list %}
    {{ item.0 }} {{ item.1 }}
{% endfor %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM