Python 循环索引模
嗨,我正试图列出一些元素,它们在每3个元素之后被clearfix div分割。这是我试过的,但不起作用。我如何在烧瓶中进行模运算Python 循环索引模,python,flask,modulo,werkzeug,Python,Flask,Modulo,Werkzeug,嗨,我正试图列出一些元素,它们在每3个元素之后被clearfix div分割。这是我试过的,但不起作用。我如何在烧瓶中进行模运算 {% for i in props %} <li class="col-xs-4"> <label class="basic-medium-black"> <span class="icon-check {% if i in user.props %}active{% endif %}"></span
{% for i in props %}
<li class="col-xs-4">
<label class="basic-medium-black">
<span class="icon-check {% if i in user.props %}active{% endif %}"></span>
{% filter upper %}{{ i.prop_name }} {% endfilter %}
</label>
</li>
****************This Part:******
{% if loop.index % 3 == 0 %}
<div class="clearfix"></div>
{% endif %}
********************************
{% endfor %}
{props%中的i的%
{%filter upper%}{{i.prop_name}{%endfilter%}
****************本部分:******
{%if loop.index%3==0%}
{%endif%}
********************************
{%endfor%}
我应该用什么来代替“%”的模呢
提前感谢。我将使用内置变量测试,如下所示
{% if loop.index is divisibleby 3 %}
或
您也可以使用来对项目进行分组,而不是使用模,这样您就可以在每个组之后进行明确的修复:
{% for row in props|batch(3) %}
{% for i in row %}
<li class="col-xs-4">
<label class="basic-medium-black">
<span class="icon-check {% if i in user.props %}active{% endif %}"></span>
{% filter upper %}{{ i.prop_name }} {% endfilter %}
</label>
</li>
{% endfor %}
<div class="clearfix"></div>
{% endfor %}
{道具中的行的百分比|批次(3)%}
{第%i行中的%i}
{%filter upper%}{{i.prop_name}{%endfilter%}
{%endfor%}
{%endfor%}
您是否在寻找与下面不同的答案?
{% for row in props|batch(3) %}
{% for i in row %}
<li class="col-xs-4">
<label class="basic-medium-black">
<span class="icon-check {% if i in user.props %}active{% endif %}"></span>
{% filter upper %}{{ i.prop_name }} {% endfilter %}
</label>
</li>
{% endfor %}
<div class="clearfix"></div>
{% endfor %}