From comments:
There's a Jinja2 extension called HTMLCompress. Its Github page.
Follow the instructions to install it and then wrap parts of markup you want to compress in {% strip %}
block:
{% strip %}
<div>
Whitespace will be removed
</div>
{% endstrip %}