'Visual Studio Code and Flask Jinja Templates

I have recently switched to Visual Studio Code (previously used PyCharm) and am now facing a formatting problem.

With the following example html:

{% extends 'base.html' %} 
{% block body %} 
{{ super() }}
  <div>Something</div>
{% endblock%}

after saving (I have turned on formatOnSave) I get the following:

{% extends 'base.html' %}{% block body %}{{ super() }}
<div>Something</div>{% endblock%}

I am using the editorconfig plugin and have stayed with the default user settings.

How can I configure VSC to not force Jinja blocks to be on a single line?



Solution 1:[1]

There's a known issue with trailing spaces.

You might try another extension dedicated to jinja: https://github.com/wholroyd/vscode-jinja

Solution 2:[2]

I have a temporary solution for that. Use Better Jinja extension and add to jinja2 files .html.j2 extension. You lose build-in HTML formatting but preserve jinja2 syntax :)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jakub Krzes?owski
Solution 2 jacek2v