我在寻找一种在django中使用模运算符的方法.我试图做的是在循环中的每四个元素中添加一个类名.
使用模数,它看起来如下所示:
{% for p in posts %}
<div class="post width1 height2 column {% if forloop.counter0 % 4 == 0 %}first{% endif %}}">
<div class="preview">
</div>
<div class="overlay">
</div>
<h2>p.title</h2>
</div>
{% endfor %}
当然,这不起作用,因为%是保留字符.有没有其他方法可以做到这一点?