【发布时间】:2013-07-16 11:55:15
【问题描述】:
模板.html
{% if leftbar.where_tab.0.location.title or leftbar.report.other_location or leftbar.report.location_description%}
{%with leftbar.where_tab.0.location.title|add:leftbar.report.other_location|add:leftbar.report.location_description as pi%}
{% if pi|length > 36 %}{{pi|slice:"36"}}...{% else %}{{pi}}{% endif %}
{% endwith %}{%else%}Where{%endif%}
我想在每个项目之间添加一个逗号(,)。现在它显示时没有任何逗号,它全部显示在一行中。项目之间需要一个分隔符,而不是最后。
【问题讨论】:
-
我在这里看不到循环。多个项目来自哪里?
-
if不是循环。这是一个条件检查。要实现您正在寻找的内容,您需要一个模板标签。如果您尝试通过模板进行操作,它可能会变得非常混乱。
标签: django django-models django-templates