3👍
You can use the join
template built-in (ref https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#join)
So your example:
<li>Producer:
{% for producer in producers %}
{% if not forloop.last %}
{{ producer }},
{% else %}
{{ producer }}
{% endif %}
{% endfor %}
</li>
would simply become:
<li>Producer:
{{ producers|join:', ' }}
</li>
0👍
You can send it as common separated string. Also it should be producers instead of producer
context = {'song': song, 'date_added': date_added, 'artist': artist,
'url': url, 'year': year, 'genres': genres, 'country': country,
'producers': ','.join(map(str, song.producer.all())), 'label': label, 'source': source,
'source_url': source_url, 'comments': comments}
- [Django]-Django calculate sum of column after multiplying each row with a different value
- [Django]-How do I know if jobs have been/are performing? – Crontab
- [Django]-WAV file from user microphone vs. WAV file from file: Some difference is causing bugs, but what are these different?
- [Django]-Creating a User Registration Page using MongoEngine
- [Django]-Pip install requirements.txt issue when deploying Django app on Heroku
Source:stackexchange.com