【发布时间】:2014-09-24 23:57:03
【问题描述】:
我有一个 django 模板负责列出一些标签,如果有通过列表sources:
<div id="selected-sources" style="min-height:150px; max-height:500px">
{% for source in sources %}
<span id='{{source.0}}' class='tag_with_remove'>
<i class='icon-remove'></i>
<span class='label'>source: {{source.1}}</span>
</span>
{% endfor %}
</div>
结果是什么:
<div id="selected-sources" style="min-height:150px; max-height:500px">
</div>
当sources 为空时。
但我希望它呈现如下:
<div id="selected-sources" style="min-height:150px; max-height:500px"></div>
这样编码是否唯一的解决方案:
<div id="selected-sources" style="min-height:150px; max-height:500px">{% for source in sources %}
<span id='{{source.0}}' class='tag_with_remove'><i class='icon-remove'></i><span class='label'>source: {{source.1}}</span></span>{% endfor %}</div>
更新: 通过小的修改,但让代码看起来有点脏,我摆脱了这个额外的换行符:
<div id="selected-sources" style="min-height:150px; max-height:500px">{% for source in sources %}
<span id='{{source.0}}' class='tag_with_remove'>
<i class='icon-remove'></i>
<span class='label'>source: {{source.1}}</span>
</span>
{% endfor %}</div>
【问题讨论】:
-
如果我是正确的,可能会在这里回答:stackoverflow.com/questions/10971553/…
-
这个包声称是一个解决方案github.com/ldiqual/django-linestripper