Reputation: 121
I am writing a for loop or if else using jinja2 templating but it is not giving me indentation in vscode. Fore example, I wrote this:
{% extends 'base.html' %}
{% block content %}
<h2>This is Item List</h2>
{% for item in items %}
<p>{{items}}</p>
{% endfor %}
{% endblock content %}
But when I press Ctrl
s
or save it manually, it loses the indentation. The code becomes like this:
{% extends 'base.html' %}
{% block content %}
<h2>This is Item List</h2>
{% for item in items %}
<p>{{items}}</p>
{% endfor %}
{% endblock content %}
This is happening for for loops, if else and everything inside jinja2 templating. Not happening in normal python codes. This is not giving any error, but I feel distressed. How to solve it.
Upvotes: 1
Views: 550
Reputation: 9209
You need to download this extension to format the .j2 file https://marketplace.visualstudio.com/items?itemName=monosans.djlint
Upvotes: 4