Dav*_*vid 9 django templating operators
我只是在学习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 \% 3 == 0 %}
<br style="clear: both"/>
{% endif %}
{% endfor %}
</ul>
Run Code Online (Sandbox Code Playgroud)
我收到语法错误,因为%是为模板语言保留的符号.这很不幸.
我已经找到了部分解决方案
{% cycle "" "" "" '<br style="clear: both"/>' %}
Run Code Online (Sandbox Code Playgroud)
但它让我感到非常奇怪.有没有更好的办法?
iMo*_*om0 26
divisibleby
如果值可以被参数整除,则返回True.
例如:
{{ value|divisibleby:"3" }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6115 次 |
| 最近记录: |