Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 957
René Jahn Avatar asked Mar 29 '18 15:03

René Jahn


People also ask

How to add Jinja template language to Visual Studio Code?

Get it now. This extension adds language colorization support for the Jinja template language to VS Code. First, you will need to install Visual Studio Code 0.10. In the command palette ( cmd-shift-p) select Install Extension and choose Jinja.

What is templating with Jinja2 in flask?

This post is part of a series called Templating With Jinja2 in Flask . Jinja2 is a template engine written in pure Python. It provides a Django -inspired non-XML syntax but supports inline expressions and an optional sandboxed environment. It is small but fast, apart from being an easy-to-use standalone template engine.

Can I use Flask Project Templates in Visual Studio?

Flask project templates are included with all earlier versions of Python Tools for Visual Studio, though details may differ from what's discussed in this tutorial. Python development is not presently supported in Visual Studio for Mac. On Mac and Linux, use the Python extension in Visual Studio Code.

How do I create a flask extended page template?

At the insertion point in the "title" block, write Home, and in the "content" block, write <p>Home page for the Visual Studio Code Flask tutorial.</p>, then save the file. These lines are the only unique parts of the extended page template:


1 Answers

There's a known issue with trailing spaces.

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

like image 61
Jakub Krzesłowski Avatar answered Oct 02 '22 15:10

Jakub Krzesłowski