RobertPro
RobertPro

Reputation: 288

Is there a code formatter for Django templates?

Where can I find a code formatter that reformats this template:

{% block content %}
{{ data|json_script:"data" }}
<div id="app">
    <app></app>
</div>

{% render_bundle 'chunk-vendors' %}
{% render_bundle 'vue-dashboard' %}

{% endblock %

to this format (notice the indentation):

{% block content %}
    {{ data|json_script:"data" }}
    <div id="app">
        <app></app>
    </div>

    {% render_bundle 'chunk-vendors' %}
    {% render_bundle 'vue-dashboard' %}

{% endblock %}

I've used PyCharm to do it, but I'm looking for a standalone tool.

Upvotes: 4

Views: 1038

Answers (1)

sur.la.route
sur.la.route

Reputation: 530

I had the same question and couldn't find anything so started a tool called djLint, with can

  • lint for common html/template issues
  • check template formatting (read:indentation)
  • reformat a template

Theres another one out there called djhtml as well, but it requires that you already have all the line breaks you need in your code.. while djLint can take a single line of sloppy html and add the needed line breaks.

Neither is a parser, so if you put in bad code, you will get bad code out :)

Upvotes: 2

Related Questions