[Answered ]-How to show the first true element after if condition in for loop in django template?

1👍

I don’t recommend doing this in Django Template , but in views itself. But if you can’t then you can use {{ forloop|break }}.

Something like this :

{% for ip in ips %}
   {% if d.name == ip.name %}
        {{ forloop|break }}
        <strong>{{ d.name}} </strong>                               
   {% endif %}
{% endfor %}

Check the small snippet example here

Leave a comment