User User - 1 month ago 8
HTML Question

(Django) line breaking in template goes to a space

For simple template

{% with var1="super" var2="man" %}
<p>
{{ var1 }}
{{ var2 }}
</p>
{% endwith %}


gives
super man
but I want
superman
.

{% spaceless %}
does not work for this case (between two strings, not two tags.)

What is the solution? Making
{{ var1 }}
and
{{ var2 }}
in one line is actually too long in my code.

Answer

The solution is simple, just remove the enter character:

{% with var1="super" var2="man" %}
    <p>
        {{ var1 }}{{ var2 }}
    </p>
{% endwith %}

But if you don't want to make the code as you said "long" ( I don't know the reason :) ), you can combine the variables two by two and merge them and so on.

Needless to say, as long as you have HTML file, it will interpret the enter character as a space in <p></p>, so your problem isn't really a django/python problem, because the problem is between the tags, not the tags themselves.