Reputation: 623
I want to display list of objects in one line using django template tags, That piece of code:
{% for object in my_objects %}
<p> {{ object }} </p>
{% endfor %}
gives me that kind of result:
obj1
obj2
obj3
.
.
.
etc.
Is there any way, to get that kind of result(with comas):
obj1, obj2, obj3, ... etc.
Thank You for anwsers.
Upvotes: 2
Views: 4325
Reputation: 2166
Simpler solution than the one given by Totem:
{{ my_objects|join:', ' }}
Upvotes: 6
Reputation: 543
Did you try ?
<p>
{% for object in my_objects %}
{{ object }}{% if not forloop.last %},{% endif %}
{% endfor %}
</p>
Upvotes: 6