skillfed

djhtml

Django/Jinja template indenter

djhtml v3.0.11 507.2K downloads/30d#6,283 on PyPI643
Copyleft license GPLv3+ Active released

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 djhtml

uv

uv add djhtml

poetry

poetry add djhtml

Installing 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

License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)Operating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9

Tags

django template indenterjinja template formatterhtml template whitespacedjango code formattertemplate auto-indent toolpre-commit html formattermixed template indentation
djangojinjapre-commit

More HTML packages