Home  >  Q&A  >  body text

python - django模板文件中{%for%}循环可以对两个对象同时循环么?

PHP中文网PHP中文网2741 days ago272

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 09:24:05

    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.

    reply
    0
  • Cancelreply