I have the following code:
{% for item in profile.jobs.all %}
{% if not forloop.first %}, {% endif %}{{ item }}
{% endfor %}
Which produces something like the following:
"Programmer , Plumber , Philosopher"
I do not want the leading space before the comma, but the only way I've been able to get rid of it is to compress it onto one line, which reduces readability:
{% for item in profile.jobs.all %}{% if not forloop.first %}, {% endif %}{{ item }}{% endfor %}
Is there a better way to deal with this?
{% spaceless %} only strips spaces between html tags.
You can either use {{ value|join:", " }}
or I believe this will work:
{% for item in profile.jobs.all %}
{% if not forloop.first %}, {% endif %}
{{ item }}
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With