--- id: djhtml version: "3.0.11" license: GPLv3+ license_treatment: copyleft maintenance: active --- # djhtml — Django/Jinja template indenter License: copyleft · Maintenance: active · Downloads: 507.2K/mo ## 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 above — 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 pip install djhtml uv add djhtml 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: unspecified - Install friction: low - Maintenance: active - Downloads: 507.2K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django template indenter, jinja template formatter, html template whitespace, django code formatter, template auto-indent tool, pre-commit html formatter, mixed template indentation, django, jinja, pre-commit [View on SkillFed](https://skillfed.io/packages/djhtml) · [View on PyPI](https://pypi.org/project/djhtml/)