dj Lint

检查并格式化你的HTML模板

技术栈里的每种语言都有格式化和检查工具,唯独 HTML 模板没有。普通 HTML 工具无法解析 {% %}{{ }},模板引擎也不关心标记的排版。djLint 填补了这个盲区:既能格式化带模板语法的 HTML,也能检查常见错误,并为 Django、Jinja、Twig、Nunjucks、Handlebars、Liquid、Go 模板等提供预设配置。

pip install djlint

你喜欢的模板语言!

输入混乱,输出整洁。

messy.html

{% block content %}
<SECTION class="posts">


<h2>Latest posts</h2>
{%if posts%}
<ul>
{% for post in posts %}
<li>
<a href="{% url 'post' post.slug %}" class="post-link {%if post.featured%}is-featured{%endif%}" data-analytics-id="post-{{post.id}}" aria-label="Read {{post.title}}">{{post.title|title}}</a>
</li>
{% endfor %}
</ul>
{%else%}
<p>No posts yet.</p>
{%endif%}
</SECTION>
{% endblock %}

djlint messy.html --reformat --single-attribute-per-line

{% block content %}
    <section class="posts">
        <h2>Latest posts</h2>
        {% if posts %}
            <ul>
                {% for post in posts %}
                    <li>
                        <a
                            href="{% url 'post' post.slug %}"
                            class="post-link {% if post.featured %}is-featured{% endif %}"
                            data-analytics-id="post-{{ post.id }}"
                            aria-label="Read {{ post.title }}"
                        >{{ post.title|title }}</a>
                    </li>
                {% endfor %}
            </ul>
        {% else %}
            <p>No posts yet.</p>
        {% endif %}
    </section>
{% endblock %}

看看你的格式!

在你项目中添加一个badge readme.md:
[![Code style: djLint](https://img.shields.io/badge/html%20style-djLint-blue.svg)](https://github.com/djlint/djlint)
在你项目中添加一个badge readme.rst:
.. image:: https://img.shields.io/badge/html%20style-djLint-blue.svg
      :target: https://github.com/djlint/djlint

实际效果:

https://github.com/djlint/djlint

参与贡献

欢迎参与贡献。你可以提交一个包含新功能的PR,或者查看 issue 列表,并在你力所能及的地方提供帮助。

编辑此页 最后更新 Aug 6, 2026