Generic HTML tools can't parse {% %} and {{ }}, and template engines don't care what the markup around them looks like. So indentation drifts, tags go unclosed and spacing goes wherever, and none of it gets caught in review.
djLint reads HTML and the template syntax inside it, with profiles for Django, Jinja, Twig, Nunjucks, Handlebars, Liquid, Go templates and more. It runs from the command line, as a pre-commit hook and as a language server in your editor.
Add it to your project as a development dependency with uv, or install it with pip. In a JavaScript project, npm adds it with a Python of its own:
uv add --dev djlint
# or
pip install djlint
# or
npm i -D djlint
Put uv run or npx in front of the commands below if you used uv or npm, as in uv run djlint . --lint. The installation guide also covers installing it as a standalone tool, and with pipx or Homebrew.
Lint your project:
djlint . --lint
See what formatting would change:
djlint . --check
Format the files in place:
djlint . --reformat
Set a --profile for the rules and formatting of your template language:
djlint . --reformat --profile=django
Or run it with pre-commit, formatting first and then linting:
repos:
- repo: https://github.com/djlint/djLint
rev: v1.54.2 # use the latest version instead
hooks:
- id: djlint-reformat
- id: djlint