Django templates: Group items in Threes

前端 未结 6 583
感情败类
感情败类 2020-12-05 22:24

I have an odd problem with Django. I have a set of objects that Im looping through in a template as you would normally. However, I need to group the items in threes. The lay

6条回答
  •  旧时难觅i
    2020-12-05 22:41

    {% for painting in painting_list %}
        
    {{ painting }}
    {% if forloop.counter|divisibleby:"3" %}
    {{ description_list.forloop.counter0-2 }} {{ description_list.forloop.counter0-1 }} {{ description_list.forloop.counter0 }} {% endif %} {% endfor %}

    just so you know this code won't work, but something like this is what you want.

    Maybe you could come up with your own templatetag to access the nth object in an object list.

提交回复
热议问题