Django counter in loop to index list

前端 未结 5 432
鱼传尺愫
鱼传尺愫 2020-12-29 12:33

I\'m passing two lists to a template. Normally if I was iterating over a list I would do something like this

{% for i in list %}

but I hav

5条回答
  •  情深已故
    2020-12-29 13:10

    Sounds like you're looking for my django-multiforloop. From the README:

    Rendering this template

    {% load multifor %}
    {% for x in x_list; y in y_list %}
      {{ x }}:{{ y }}
    {% endfor %}
    

    with this context

    context = {
        "x_list": ('one', 1, 'carrot'),
        "y_list": ('two', 2, 'orange')
    }
    

    will output

    one:two
    1:2
    carrot:orange
    

提交回复
热议问题