question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

request to add support for Jinja2 and Django template tags indention

See original GitHub issue

I’m currently using vscode and have some extensions installed and some configuration for those extensions applied. Django by Baptiste Darthenay and Beautify by HookyQR, are the extensions and this is the settings:

"files.associations": {
	"**/*.html": "html",
	"**/templates/**/*.html": "django-html", // this is provided by Django ext.
},
"beautify.language": {
	"html": ["django-html"]
},
"[django-html]": {
	"editor.defaultFormatter": "HookyQR.beautify",
}

it is very helpful since it will indent the html tags inside Django-templates but it doesn’t do anything with Jinja2 or Django-template syntax (which is really similar but not exactly jinja). I hope there would be a solution to have the indention for this syntax too. it currently looks like this:

<div class="card-data">
    <ul class="list-unstyled">
        <li class="comment-date font-small">
            <i class="far fa-clock-o"></i>
            {% if LANGUAGE_BIDI %}
            {{ comment.created|to_jalali:'%H:%M %B %d, %Y' }}
            {% else %}
            {{ comment.created }}
            {% endif %}
        </li>
    </ul>
</div>

imagine the ugly code when using nested template tags. thanks for your attention.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:6

github_iconTop GitHub Comments

1reaction
mh-firouzjahcommented, Aug 29, 2022

@Zymonick hello. that indentation rule I pasted here was for vscode custom language extension, I added to Django extension of Baptist-Dartenay(sorry if I spelled it wrong) and there the rules worked but that was not complete as it worked just when I was typing the code but it couldn’t format on save or… anyway the HookyQR.beautify is not maintained anymore is signed as deprecated. the djlint extension for vscode is working well and I’m using it.

0reactions
Zymonickcommented, Aug 29, 2022

oh great, thank you very much for the very quick reply. I installed djilint and it works very well!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Template Designer Documentation - Jinja
A template contains variables and/or expressions, which get replaced with values when a template is rendered; and tags, which control the logic of...
Read more >
Jinja2 correctly indent included block - Stack Overflow
Good question. I believe Jinja2 does not do this. The main question you need to ask yourself is why you want the HTML...
Read more >
rtts/djhtml: Django/Jinja template indenter - GitHub
DjHTML is a fully automatic template indenter that works with mixed HTML/CSS/Javascript templates that contain Django or Jinja template tags. It works similar ......
Read more >
HTML indentation broken when Jinja tags are used : PY-11159
Attempting to run the code format while Jinja is set as the template language will not move the lis into the correct column...
Read more >
jinja2 indentation with gg=G - Vi and Vim Stack Exchange
You will probably have to do this yourself, by copying the HTML indent file, and modify it so that it recognized Django-style blocks....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found