简体   繁体   中英

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. 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. 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. For me the easiest way to go is to prepare your context data better in the respective view prior to rendering the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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