Comma separated lists in django templates

后端 未结 11 1382
梦如初夏
梦如初夏 2021-01-30 16:00

If fruits is the list [\'apples\', \'oranges\', \'pears\'],

is there a quick way using django template tags to produce \"apples, oranges, and p

11条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-30 16:21

    If you want a '.' on the end of Michael Matthew Toomim's answer, then use:

    {% if not forloop.last %}{% ifequal forloop.revcounter 2 %} and {% else %}, {% endifequal %}{% else %}{% endif %}{% if forloop.last %}.{% endif %}
    

提交回复
热议问题