Formatter Usage

djLint’s formatter will take sloppy html templates and make the formatting consistent and easy to follow!

Formatting is a beta tool. --check the output before applying changes.

To review what may change in formatting run:

djlint . --check

To format the code and update files run:

djlint . --reformat

# how about formatting scripts and styles?
djlint . --reformat --format-css --format-js

Note

Reformatting does not work with long json/html embedded into attribute data.

Note

djLint is not an html parser or syntax validator.

Here’s an example!

Before

Here’s a blob of HTML that’s in desperate need of attention -

{% load admin_list %}{% load i18n %}<p class="paginator">{% if pagination_required %}{% for i in page_range %}{% paginator_number cl i %}{% endfor %}{% endif %}{{ cl.result_count }}{% if cl.result_count == 1 %}{{ cl.opts.verbose_name }}   {% else %}{{ cl.opts.verbose_name_plural }}       {% endif %}{% if show_all_url %} <a href="{{ show_all_url }}" class="showall">{% translate 'Show all' %}          </a>  {% endif %}{% if cl.formset and cl.result_count %}<input type="submit" name="_save" class="default" value="{% translate 'Save' %}">{% endif %}      </p>

After

It looks a bit better now… we can read it :)

{% load admin_list %} {% load i18n %}
<p class="paginator">
{% if pagination_required %} {% for i in page_range %} {% paginator_number cl
i %} {% endfor %} {% endif %} {{ cl.result_count }} {% if cl.result_count == 1
%} {{ cl.opts.verbose_name }} {% else %} {{ cl.opts.verbose_name_plural }} {%
endif %} {% if show_all_url %}
<a href="{{ show_all_url }}" class="showall"> {% translate 'Show all' %} </a>
{% endif %} {% if cl.formset and cl.result_count %}
<input
type="submit"
name="_save"
class="default"
value="{% translate 'Save' %}"
/>

{% endif %}
</p>
Edit this page Updated Jul 28, 2022