djhtml
Django/Jinja template indenter
What it is and what it does
DjHTML is a pure-Python indentation tool designed specifically for Django and Jinja templates that mix HTML, CSS, and JavaScript. Unlike general formatters, it operates as an indenter—it adjusts only leading whitespace on each line without inserting newlines, removing content, or restructuring code. This makes it suitable for fixing indentation in already well-structured templates while leaving the template logic and content untouched.
The tool works as a command-line utility and integrates cleanly with pre-commit hooks for automated indentation on every commit. It supports three modes (DjHTML, DjCSS, and DjJS) that activate automatically when encountering style or script tags, and allows fine-grained control via command-line options like custom tab width and extra block tag definitions. It also respects fmt:off/fmt:on markers and ignores content inside comments and special template tags.
Use it for:
- Automatically indent all Django templates in a project before each commit using pre-commit hooks.
- Fix indentation inconsistencies in Jinja templates across a codebase without altering template logic.
- Maintain consistent whitespace in mixed HTML/CSS/JavaScript template files during development.
- Dry-run indentation checks on templates using the --check flag to verify formatting without modifying files.
- Define custom block tags for non-standard template syntax and apply consistent indentation rules.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
DjHTML indents Django and Jinja template files containing mixed HTML, CSS, and JavaScript by adding or removing leading whitespace, without inserting newlines or reformatting content.
Yes. DjHTML is actively maintained, has no runtime dependencies, installs easily, and solves a specific problem well—indenting Django/Jinja templates without reformatting content. The GPLv3+ license is a consideration for proprietary projects, but the tool is ideal for open-source Django/Jinja workflows, especially when integrated with pre-commit. No known security vulnerabilities.
Install
djhtml on PyPI
pip
pip install djhtmluv
uv add djhtmlpoetry
poetry add djhtmlInstalling djhtml
Before you install
Installation is straightforward with no runtime dependencies. The package is actively maintained with recent releases and a stable repository. Requires Python 3.9 or higher.
License in practice
Licensed under GPLv3+, a copyleft license. Any derivative work or distribution must also be open-source under compatible terms; proprietary projects cannot incorporate this package without releasing their modifications.
Quickstart
$ pip install djhtml
$ djhtml template.html
# Or use as a pre-commit hook by adding to .pre-commit-config.yaml:
# - repo: https://github.com/rtts/djhtml
# hooks:
# - id: djhtml
Windows users should set the environment variable PYTHONUTF8 to 1 to ensure proper UTF-8 handling.
Verify before relying
- Whether the package correctly handles all edge cases in nested Django/Jinja template structures.
- Performance characteristics on very large template files or directories with thousands of files.
Package facts
| License | GPLv3+ (copyleft) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 141 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 507,180/month — #6,283 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: djhtml-3.0.11-py3-none-any.whl
Tags
More HTML packages
MarkupSafe provides a text object that escapes…
permissive · top 100 on PyPI
Jinja2Jinja2 is a templating engine that renders…
permissive · top 100 on PyPI
beautifulsoup4Beautiful Soup parses HTML and XML documents…
permissive · top 100 on PyPI
lxmllxml provides Python bindings to libxml2 and…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
MarkdownConverts Markdown text to HTML using a Python…
permissive · top 1,000 on PyPI
djlintdjlint formats and lints HTML templates with…
copyleft · top 5,000 on PyPI
djadeDjade is a command-line formatter for Django…
permissive · top 15,000 on PyPI
django-settings-exportProvides a Django template context processor…
permissive · top 15,000 on PyPI
curlylintLints HTML templates in Jinja, Nunjucks,…
permissive · top 15,000 on PyPI
jinja_partialsAdds a `render_partial()` function to Jinja2…
permissive · top 5,000 on PyPI
j2lintj2lint validates Jinja2 template syntax and…
permissive · top 15,000 on PyPI
sphinx-jinjaA Sphinx extension that lets you embed Jinja2…
permissive · top 5,000 on PyPI
xmlformatterFormats and compresses XML documents by…
permissive · top 15,000 on PyPI
reformat-gherkinAutomatically formats Gherkin feature files to…
permissive · top 15,000 on PyPI