【发布时间】:2017-09-04 14:51:08
【问题描述】:
我尝试使用 forloop.last 模板标签
<div class="panel-body">
{% for card in cardlist.card_set.all %}
{% if forloop.last %}
<div class="well" style="margin-bottom: 0px;">{{ card.title }}</div>
{% else %}
<div class="well" style="margin-bottom: 20px;">{{ card.title }}</div>
{% endif %}
{% endfor %}
</div>
如何像下面的源一样重构上面的源?
在重构的源代码中,“margin-bottom: {{margin-bottom}} px;” “{{margin-bottom}}”中的错误。
<div class="panel-body">
{% for card in cardlist.card_set.all %}
{% if forloop.last %}
margin-bottom = 0
{% else %}
margin-bottom = 20
{% endif %}
<div class="well" style="margin-bottom: {{ }}px;">{{ card.title }}</div>
{% endfor %}
</div>
【问题讨论】:
-
{{margin-bottom}}这将导致错误,因为-被认为是减号
标签: css django templatetag