Remove Duplicate List in Jinja

Remove Duplicate List in Jinja

Im populating my html page using jinja, how can I remove duplication from output like using set() in python?

below is my code :

<label class="text-primary" for="search_type" style="display:inline-block;">Selected Status : </label>
{% for project_data in project_on_status_list %}
    <span>{{ project_data.get_project_stage_display }}, </span>
{% endfor %}

Output :

Selected Status :  In Progress, On Hold, On Hold, Completed,

Desired Output :

Selected Status :  In Progress, On Hold, Completed,
8

1 Answer

You need filter unique

`<label class="text-primary" for="search_type" style="display:inline-block;">
Selected Status : 
</label>
{% for project_data in project_on_status_list %}
<span>{{ project_data.get_project_stage_display | unique }}, </span>
{% endfor %}`
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.