删除jinja中的重复列表

时间:2017-12-05 08:04:48

标签: python html jinja2

我使用jinja填充我的html页面,如何在python中使用set()删除输出中的重复?

下面是我的代码:

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


输出:

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

期望的输出:

Selected Status :  In Progress, On Hold, Completed,

1 个答案:

答案 0 :(得分:0)

您需要过滤器唯一

`<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 %}`