How to output a comma delimited list in jinja python template?

前端 未结 3 865
半阙折子戏
半阙折子戏 2020-12-22 16:56

If I have a list of users say [\"Sam\", \"Bob\", \"Joe\"], I want to do something where I can output in my jinja template file:

{%          


        
3条回答
  •  甜味超标
    2020-12-22 17:18

    You want your if check to be:

    {% if not loop.last %}
        ,
    {% endif %}
    

    Note that you can also shorten the code by using If Expression:

    {{ ", " if not loop.last }}
    

提交回复
热议问题