django-despacer - Removes excess whitespace (blank lines and floating text) in DTL's generated HTML

django-despacer is a new PyPI package that is a lightweight loader for the Django Template Language (DTL). It enables removing excess whitespace by using delimiters like {#- and -#} (similar to Jinja2, Golang, PHP’s Twig). It’s lightweight because it adds just two regular expressions that run at template loading time and nothing at request handling time.

This package is intended as a demonstration of this feature. I’m hoping this feature will eventually be included in Django’s core code, at which time this package will no longer be needed.

2 Likes

Nice one! I’d love this feature in DTL. It sounds like it wouldn’t be too much work…

I also think this would be a really nice addition to Django templating!

Inability to control excess whitespace in Django templates is one of those small paper cuts that I’ve just slowly accepted over time. Then when using something like Golang templating I’m reminded of how much nicer things can be.

Thanks. I’ve opened a new feature request if you’d like to support it.