Comma separated lists in django templates

后端 未结 11 1195
梦如初夏
梦如初夏 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:18

    First choice: use the existing join template tag.

    http://docs.djangoproject.com/en/dev/ref/templates/builtins/#join

    Here's their example

    {{ value|join:" // " }}
    

    Second choice: do it in the view.

    fruits_text = ", ".join( fruits )
    

    Provide fruits_text to the template for rendering.

提交回复
热议问题