Django Smart Spaceless¶
Django Smart Spaceless is a Django template tag application for minifying block-level HTML elements only.
It’s just like spaceless
, but preserves white space between inline HTML elements. Useful for HTML where spaces directly between <a>
, <strong>
, and other inline elements is likely desired to be preserved. Packages the django-htmlmin project to be used as a template tag.
Install¶
$ pip install django-smartspaceless
Add to settings.py
.
INSTALLED_APPS = [
# ...
'smartspaceless',
]
Usage¶
{% load smartspaceless_tags %}
{% smartspaceless %}
<p><a href="#">Link 1</a></p>
<p><a href="#">Link 2</a> <a href="#">Link 3</a></p>
{% endsmartspaceless %}
Result:
<p><a href="#">Link 1</a></p><p><a href="#">Link 2</a> <a href="#">Link 3</a></p>
Note that the space between <a href="#">Link 2</a>
and <a href="#">Link 2</a>
is preserved. Removing that space would be bad.