【发布时间】:2011-11-13 05:40:33
【问题描述】:
我只是在学习 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>
我收到语法错误,因为 % 是为模板语言保留的符号。这很不幸。
我已经找到了部分解决方案
{% cycle "" "" "" '<br style="clear: both"/>' %}
但这让我觉得很奇怪。有没有更好的办法?
【问题讨论】:
标签: django operators templating