当对象的主键是 1,4,7...等时,我需要运行一段代码。基本上,我需要为某个代码块运行 if 语句。
{% with i = ev.pk %}
{% if i%3 == 1 %}
<div class="container">
<div class="intro"></div>
<div class="row articles">
{% endif %}
{% endwith %}
<div class="col-sm-6 col-md-4 item" data-aos="fade-left"><a href="#"><img class="img-fluid" src="{{ ev.image.url }}"></a>
<h3 class="name">{{ ev.event_title }}</h3>
<p class="description">{{ event.event_details }}</p><em class="float-left">{{ ev.date }}</em><em class="float-right">{{ ev.venue }}</em></div>
</div>
</div>
{% endfor %}```
The above code doesn't work, I need:
1. Declare a variable (i)
2. assign it ev.pk
3. run an if statement {% if i%3 == 1%}
I am open for suggestions if there is a better way to code this.