How do I get odd and even values in a Django for loop template?

后端 未结 4 835
耶瑟儿~
耶瑟儿~ 2020-12-01 04:21

I have this code

{% for o in some_list %}

Now I want to do some stuff if I am on an even line. How can I do that?

4条回答
  •  不知归路
    2020-12-01 04:55

    {% for post in posts %} {% if loop.index is divisibleby 2 %}
    Even posts
    {% else %}
    Odd posts
    {% endif %} {% endfor %}

    http://mitsuhiko.pocoo.org/jinja2docs/html/templates.html#id3

提交回复
热议问题