Iterating through two lists in Django templates

前端 未结 7 2255
甜味超标
甜味超标 2020-11-27 04:43

I want to do the below list iteration in django templates:

foo = [\'foo\', \'bar\'];
moo = [\'moo\', \'loo\'];

for (a, b) in zip(foo, moo):
    print a, b
<         


        
7条回答
  •  暖寄归人
    2020-11-27 05:14

    It's possible to do

    {% for ab in mylist %}
        {{ab.0}}
        {{ab.1}}
    {% endfor %}
    

    but you cannot make a call to zip within the for structure. You'll have to store the zipped list in another variable first, then iterate over it.

提交回复
热议问题