Include Django template without new line

My main.html template contains the following code:

 <p>{% include "pouac.html" %}{% include "pouac.html" %}</p> 

The pouac.html file contains one line:

 <span>pouac</span> 

The main.html template creates the following lines two html codes:

 <span>pouac</span> <span>pouac</span> 

The disgusting side effect is that this code creates some space between the two words "pouac" (for example: "word1" and "word2" are separated by a space in http://jsfiddle.net/regisb/CBtaz/ )

To get rid of this gap, I would like to make a Django template without adding an extended line break. How can i do this?

+4
source share
2 answers

You can use the template tag without spaces [1].

 {% spaceless %}{% include "pouac.html" %}{% include "pouac.html" %}{% endspaceless %} 

[1] https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#spaceless

+9
source

You might want to wrap it in Django with the built-in `spacless' template tag:

 <p>{% spaceless %}{% include "pouac.html" %}{% include "pouac.html" %}{% endspaceless %}</p> 
+5
source

Source: https://habr.com/ru/post/1487294/


All Articles