Alternate Row Coloring in Django Template with More Than One Set of Rows

前端 未结 7 1175
广开言路
广开言路 2020-12-07 14:37

Django templates offer the builtin tag cycle for alternating between several values at different points in a template (or for loop in a template) but this tag d

7条回答
  •  一个人的身影
    2020-12-07 15:12

    The easiest workaround (until the resetcycle patch gets fixed up and applied) is to use the built-in "divisibleby" filter with forloop.counter:

    {% for entry in blog.entries %}
      
    {{ entry.text }}
    {% endfor %}

    A little more verbose, but not hard to understand and it works great.

提交回复
热议问题