【发布时间】:2015-05-21 08:10:49
【问题描述】:
所以在我的模板中,我只需要在 for 循环中打印一次语句,即使它迭代了很多次。我的代码是:
{% for interview in scheduledinterviews %}
{% if interview.slot.start.date == today.date %}
<div class="row">
<div class="col-xs-12 profile-dash">
<h4>Today's Interviews</h4>
</div>
</div>
我只需要打印一次 Todays Interview,因为它满足循环内的 if 条件。我该怎么办?
【问题讨论】:
-
你想做什么?您是否要检查预定的面试是否不为空?你可以像 {% if scheduledinterviews %) Today Interviews{%endif%}
-
如果你只想运行你的 for 循环,你可以使用 slice!比如 {% interview in scheduledinterviews|slice:"1" %}
标签: python django django-templates