django template turn array into HTML table

后端 未结 3 1037
悲哀的现实
悲哀的现实 2021-02-02 17:32

I have a list of 16 results, let\'s call it \"results\". I want to arrange them in a 4 x 4 table.

Using the django template, how can I do this? (It doesn\'t seem like cy

3条回答
  •  攒了一身酷
    2021-02-02 17:43

    You can use the cycle tag for this.

    
      {% for r in results %}
        {% cycle '' '' '' '' %}
          
        {% cycle '' '' '' '' %}
      {% endfor %}
    
    {{r.content}}

    Would output something like...

    result 1 result 2 result 3 result 4
    result 5 result 6 result 7 result 8

提交回复
热议问题