当对象的主键为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.
答案 0 :(得分:0)
这可能会起作用(使用tff.federated_collect()
):
{% with ev.pk as i %}
{% if i|divisibleby:3 %}
<div class="container">
<div class="intro"></div>
<div class="row articles">
{% endif %}
{% endwith %}