In Rails ERB, you can suppress newlines by adding a trailing hyphen to tags:
<ul>
<% for @item in @items -%>
<li><%= @item %></li>
<% end -%>
</ul>
becomes:
<ul>
<li>apple</li>
<li>banana</li>
<li>cacao</li>
</ul>
Is there a way to do this in Django? (Disclosure: I'm generating a csv file with Django)
Edit: Clarified that the newlines I'm hunting down are the ones left behind after the template tags.
POST form (your current approach) This answer is perfect and I learned a great deal!
extends tag is used for inheritance of templates in django. One needs to repeat the same code again and again. Using extends we can inherit templates as well as variables.
lorem. Displays random “lorem ipsum” Latin text. This is useful for providing sample data in templates.
A variable is a symbol within a template that outputs a value. Variable tags are surrounded by {{ and }} : My first name is {{ first_name }}. My last name is {{ last_name }}.
The closest I've found to what you're looking for (I'm looking for the same thing) is talk about a future patch, here: http://code.djangoproject.com/ticket/2594.
Unfortunately, it looks like there's not much you can do until they merge that patch in.
{% spaceless %}
<ul>
<li>apple</li>
<li>banana</li>
<li>cacao</li>
</ul>
{% endspaceless %}
I am not aware about any way to discard template tags lines. I'd vote for opening bug report.
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