在谷歌应用引擎模板中使用"范围" - 循环

0 python django-templates

我有一个appengine项目,在我的模板中我想做类似的事情

{% for i in range(0, len(somelist)) %}
  {{ somelist[i] }} {{ otherlist[i] }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

我已经尝试使用'forloop.counter'来访问列表项,但这也没有用.有什么建议?

问候,复数

Mil*_*les 6

您可能想要做的是将您传入的数据更改为模板,以便将某些列表和其他列表压缩到一个列表中:

combined_list = zip(somelist, otherlist)
...
{% for item in combined_list %}
    {{ item.0 }} {{ item.1 }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)