django模板中的模/模等价运算符/函数?
我只是在学习django的模板系统,并尝试做一些相对简单的事情:django模板中的模/模等价运算符/函数?,django,operators,templating,Django,Operators,Templating,我只是在学习django的模板系统,并尝试做一些相对简单的事情: <h2>State</h2> <ul class="states"> {% for state in states %} <li class="state_elements" ><a href="/{{ state.name }}/"> {{ state.name }}</a></li> {% if forloop.counter \%
<h2>State</h2>
<ul class="states">
{% for state in states %}
<li class="state_elements" ><a href="/{{ state.name }}/"> {{ state.name }}</a></li>
{% if forloop.counter \% 3 == 0 %}
<br style="clear: both"/>
{% endif %}
{% endfor %}
</ul>
状态
{状态为%的状态为%}
{%if-forloop.counter\%3==0%}
{%endif%}
{%endfor%}
我得到一个语法错误,因为%是为模板语言保留的符号。这是不幸的
我已经找到了一个部分解决方案
{% cycle "" "" "" '<br style="clear: both"/>' %}
{%cycle”“”“”
'%}
但我觉得很奇怪。有更好的方法吗?可除法 如果值可被参数整除,则返回True 例如:
{{ value|divisibleby:"3" }}
可被2整除的福洛普计数
{% if forloop.counter|divisibleby:2 == 0 %}
循环计数不能被2整除
{% if forloop.counter|divisibleby:2 != 0 %}
所以只要检查一下是否正常,我可以像{%for.counter | divisibleby:“3”}
{%endif%}{%if-forloop.counter | divisibleby:“3”}这样做吗