Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django模板循环_Python_Django - Fatal编程技术网

Python django模板循环

Python django模板循环,python,django,Python,Django,我可以同时循环django模板中的两个数组/列表吗 大概是这样的: # views.py a = [{'a':'apple','b':'banana','c':'clementine'}, {'a':'aunt','b':'brother','c':'cousin'}, {'a':'ant','b':'bat','c':'cat'}] b = [{'d':'dave','f':'fred'}, {'d':'dason','f':'ford'}, {'d'

我可以同时循环django模板中的两个数组/列表吗

大概是这样的:

# views.py

a = [{'a':'apple','b':'banana','c':'clementine'},
     {'a':'aunt','b':'brother','c':'cousin'},
     {'a':'ant','b':'bat','c':'cat'}]
b = [{'d':'dave','f':'fred'},
     {'d':'dason','f':'ford'},
     {'d':'dance','f':'flamenco']

# something.html

{% for x, y in a and b %}
    {{ x.a }},{{ x.c }}<br>
    {{ y.f }}
{% endfor %}
#views.py
a=[{'a':'apple','b':'banana','c':'clementine'},
{'a':'姨妈','b':'兄弟','c':'表弟'},
{'a':'ant','b':'bat','c':'cat'}]
b=[{'d':'dave','f':'fred'},
{'d':'dason','f':'ford'},
{'d':'dance','f':'flamenco']
#something.html
{a和b%中x,y的百分比}
{x.a},{x.c}}
{{y.f}} {%endfor%}
您可以在视图中选择这两个列表,然后在模板中遍历生成的列表

# views.py
ab = zip(a,b)

# template
{% for x,y in ab %}
    {{ x.a }},{{ x.c }}<br>
    {{ y.f }}
{% endfor %}
#views.py
ab=zip(a,b)
#模板
{ab%中x的%y}
{x.a},{x.c}}
{{y.f}} {%endfor%}
cool。我会试一试。我之所以问这个问题,是因为当我迭代表单时,我想使用模型的某些方面