Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert list to comma separate values in django template

Tags:

python

django

In a view I can do:

l = ['one', 'two', 'three']
', '.join(l)
>>> 'one, two, three'

Is there a way to do the same in the template, or do I need to create a custom template filter?

like image 943
David542 Avatar asked Oct 14 '14 20:10

David542


1 Answers

There is a builtin filter for this. From the docs

Filter arguments that contain spaces must be quoted; for example, to join a list with commas and spaces you’d use {{ list|join:", " }}.

like image 131
C.B. Avatar answered Sep 18 '22 12:09

C.B.