如何在 html 中为主键声明一个变量并在 'if' 语句中使用它

how to declare a variable in html for primary key and use it in an 'if' statement

当对象的主键是 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.


可能这会起作用(使用 divisibleby):

{% with ev.pk as i %}
       {% if i|divisibleby:3 %}
       <div class="container">
           <div class="intro"></div>
           <div class="row articles">
       {% endif %}
{% endwith %}