A
A
Andrew2012-05-07 00:45:27
Django
Andrew, 2012-05-07 00:45:27

Removing empty line breaks from page code

Good afternoon!
There is a django template, there are a bunch of different ones . So, this construction gives two empty newlines before and after {{ el }}, the question is: How to avoid this without resorting to the {% spaceless %} tag? Thank you!
{% if ... %}
{% for el in list %}
{{ el }}
{% endfor %}
{% endif %}


Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
kmike, 2012-05-07
@kmike

Normally, no way. Place tags on one line. You can cut out the regexp in the middleware, but this evil is already some kind, worse than the spaceless tag. See code.djangoproject.com/ticket/2594
You can also use Jinja2 instead of django templates if empty lines are very annoying, or you can patch django (or fake patch only the right places) with a patch from the ticket. Or score.

A
Andrew, 2012-05-07
@xmdy

I remembered about solutions for nginx, but it needs to be rebuilt with the necessary parameters ... Zhzhzhopa))
Why is jinja2 better? Does she cut herself?

C
chuwy, 2012-05-07
@chuwy

In some cases, it may be justified to add methods to the model that will output everything as it should (without HTML only, God forbid).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question