How to remove white space from html source code How to remove white space from html source code django django

How to remove white space from html source code


You can use the spaceless template tag. It:

Removes whitespace between HTML tags.

{% spaceless %}<p>    <a href="foo/">Foo</a></p>{% endspaceless %}


  1. Look toward middelware, eg "htmlmin". It processes the file at a time. In addition it has a decorator.https://crate.io/packages/django-htmlmin

  2. gzip will give the same effect. Probably would have cost to opt out of trimming.Look towards django middelware or nginx gzip.

  3. You use the controller/model logic in the template. This is wrong way.