简体   繁体   English

只需要在for循环内打印一次语句-Django

[英]Need to print the statement inside for loop only once - Django

SO in my template i need to print a statement only once inside the for loop even it iterates many times. 所以在我的模板中,即使迭代多次,我也只需要在for循环内打印一次语句。 my code is : 我的代码是:

{% 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>

I need to Print Todays Interview only once as it satisfies the if condition inside the loop. 我只需要打印一次今天的采访,因为它满足循环中的if条件。 What Should i do? 我该怎么办?

您可以使用ifchanged标签。

{% ifchanged interview.slot.start.date %}<h4>Today's Interviews</h4>{% endifchanged %}

Sorry to disappoint you but there is no break tag in django template. 抱歉让您失望,但Django模板中没有break标签。 For me the easiest way to go is to prepare your context data better in the respective view prior to rendering the data. 对我来说,最简单的方法是在渲染数据之前在相应的视图中更好地准备上下文数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM