I have a list lst=['apple', 'pear', 'peach']
.
I want to show each item in textarea from new line (removing redundant subspaces).
<textarea>
{% for item in lst %}
{{ item }}
{% if not forloop.last %}<br/>{% endif %}
{% endfor %}
</textarea>
This code doesn't work. <br/>
s are shown as they are. And there are redundant whitespaces at the beginning of the textarea and between the items.
CodePudding user response:
The <textarea>
tag is very stupid:) in your template there is no place for new line and space:
<textarea>{% for item in lst %}{{ item }}{% if not forloop.last %} {% endif %}{% endfor %}</textarea>
It need to be in one line or it will break.
Line Feed and
Carriage Return as @Bukudan explain in this thread: https://stackoverflow.com/a/8627926/13773284