在Google App Engine模板中使用"range"进行循环
我有一个App Engine项目,在我的模板里我想做一些类似的事情:
{% for i in range(0, len(somelist)) %}
{{ somelist[i] }} {{ otherlist[i] }}
{% endfor %}
我试过用'forloop.counter'来访问列表里的项目,但也没有成功。有什么建议吗?
祝好,mux
1 个回答
6
你可以考虑改变一下传给模板的数据,把 somelist 和 otherlist 合并成一个列表,这样就可以一起使用了:
combined_list = zip(somelist, otherlist)
...
{% for item in combined_list %}
{{ item.0 }} {{ item.1 }}
{% endfor %}