Using spaceless in django template -


i have following code:

 {% item in profile.jobs.all %} {% if not forloop.first %}, {% endif %}{{ item }} {% endfor %} 

which produces following:

"programmer , plumber , philosopher" 

i not want leading space before comma, way i've been able rid of compress onto 1 line, reduces readability:

{% item in profile.jobs.all %}{% if not forloop.first %}, {% endif %}{{ item }}{% endfor %} 

is there better way deal this?

{% spaceless %} strips spaces between html tags.

you can either use {{ value|join:", " }}

or believe work:

{% item in profile.jobs.all %} {% if not forloop.first %}, {% endif %} {{ item }} {% endfor %} 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -