django模板中的模数/模等效运算符/函数? [英] Modulus/Modulo equivalent operator/function in django templates?
本文介绍了django模板中的模数/模等效运算符/函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在学习django的模板系统,并尝试做一些比较简单的事情:
I'm just learning django's templating system and trying to do something relatively trivial:
<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>
我收到语法错误,因为%是为模板语言保留的符号。这是不幸的。
I get a syntax error because % is a symbol reserved for the templating language. This is unfortunate.
我已经找到了
{% cycle "" "" "" '<br style="clear: both"/>' %}
但是它让我很伤心。有更好的方法吗?
but it strikes me as damn odd. Is there a better way?
推荐答案
divisibleby
如果值可被参数整除,则返回True。
例如:
{{ value|divisibleby:"3" }}
这篇关于django模板中的模数/模等效运算符/函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文