Is there way to indent Jinja2 templates in Python?

Is there way to indent Jinja2 templates in Python?

It’d be nice to use the standard way for indentation in Jinja2 templates (or something close to it). Indentation in python files is check by our Invenio-Kwalitee tool upon every pull request/commit, however there is no standard on how to indent Jinja2 HTML templates.

How to indent a page in flask-jinja2?

In a production application it is more efficient to go the other way and strip all the white space to make the page smaller. If you are interested in doing this during development then you can pass the HTML generated by render_template () through an indenter such as prettify () from BeautifulSoup.

What do you need to know about Jinja templates?

A Jinja template is simply a text file. format (HTML, XML, CSV, LaTeX, etc.). A Jinja template doesn’t need to have a specific extension:.html,.xml, or any other extension is just fine. A template contains variablesand/or expressions, which get replaced

Is it possible to process non-Unicode data in Jinja2?

It is not possible to use Jinja2 to process non-Unicode data. The reason for this is that Jinja2 uses Unicode already on the language level. For example Jinja2 treats the non- breaking space as valid whitespace inside expressions which requires knowledge of the encoding or operating on an Unicode string.

How to manage whitespace and tabular indentation in Jinja2?

According to Jinja2 documentation you can manage whitespace and tabular indentation with lstrip_blocks and trim_blocks options: trim_blocks: If this is set to True the first newline after a block is removed (block, not variable tag!). Defaults to False.

Can you write Jinja2 code without indentation in Ansible?

So, if you have following Ansible code for /etc/hosts template: By default Ansible will indent as you’re doing in your code: But if you add at the top of your template the following code: Result will be without indentation: That makes you able to write more readable jinja2 code in your templates.