django template rows of multiple items

前端 未结 4 721
梦毁少年i
梦毁少年i 2020-12-13 15:26

I\'m creating a catalogue, where there is a list of items of undefined length. I want to spit it out in rows with three columns each. So I have the following html:



        
4条回答
  •  一向
    一向 (楼主)
    2020-12-13 16:10

    Sorry don't have enough reputation to just comment jpic's answer(the accepted one), for Jinja2, use:

    {% for item in items %}
    {{ item }}
    {% if loop.index is divisibleby(3) %}
    {% endif %} {% endfor %}

    details are here.

提交回复
热议问题