python - django模板文件中{%for%}循环可以对两个对象同时循环么?
PHP中文网
PHP中文网 2017-04-18 09:22:05
0
1
303
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
Ty80

There is a standard solution for this, which iszip:

>>> l1 = ['a', 'b', 'c']
>>> l2 = ['x', 'y', 'z']
>>> l3 = zip(l1, l2)
>>> l3
[('a', 'x'), ('b', 'y'), ('c', 'z')]

Then you can just loop over l3 in the template.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template