{"id":6345,"library":"djhtml","title":"DjHTML: Django/Jinja Template Indenter","description":"DjHTML is a pure-Python Django/Jinja template indenter without external dependencies. It formats mixed HTML/CSS/JavaScript templates that incorporate Django or Jinja template tags. Similar to tools like Black, DjHTML acts as an indenter, primarily adjusting leading whitespace to ensure consistent indentation, rather than performing comprehensive code reformatting. It is actively maintained with a regular release cadence, with the latest version being 3.0.11.","status":"active","version":"3.0.11","language":"en","source_language":"en","source_url":"https://github.com/rtts/djhtml","tags":["formatting","html","django","jinja","cli","pre-commit"],"install":[{"cmd":"pip install djhtml","lang":"bash","label":"Install DjHTML"}],"dependencies":[],"imports":[],"quickstart":{"code":"mkdir djhtml_test\ncd djhtml_test\necho '{% if user.is_authenticated %}<div class=\"welcome\">Hello, {{ user.username }}!</div>{% else %}<a href=\"/login/\">Login</a>{% endif %}' > template.html\n\n# Indent a single file\ndjhtml template.html\n\n# Verify changes\ncat template.html\n\n# Indent all HTML files in the current directory and subdirectories\ndjhtml .\n\n# Example of checking without modifying (exit code 1 if changes are needed)\ndjhtml --check template.html\n","lang":"bash","description":"DjHTML is primarily a command-line tool. After installation, you can indent individual template files or an entire directory. The `djhtml .` command indents all HTML files beneath the current directory."},"warnings":[{"fix":"Upgrade Python to 3.9 or newer (e.g., `pyenv install 3.9.19 && pyenv local 3.9.19`).","message":"Support for Python 3.8 was dropped in DjHTML 3.0.7. Users on Python 3.8 or older must upgrade their Python version to 3.9 or higher to use recent DjHTML versions.","severity":"breaking","affected_versions":">=3.0.7"},{"fix":"Remove the `-q` or `--quiet` flag from your commands. For quiet output, redirect `stderr` (e.g., `djhtml template.html 2>/dev/null`).","message":"The `-q` or `--quiet` command-line option was removed in version 3.0.3. Output is now directed to stderr, allowing users to redirect stderr to `/dev/null` for quiet operation.","severity":"breaking","affected_versions":">=3.0.3"},{"fix":"Run `setx /m PYTHONUTF8 1` in an elevated command prompt to set the system-wide environment variable, or `set PYTHONUTF8=1` for the current session.","message":"On Windows, DjHTML highly advises setting the `PYTHONUTF8` environment variable to 1 to ensure correct handling of UTF-8 encoding, especially with legacy code pages.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Understand its scope: ensure your HTML is structurally sound before running DjHTML. For full formatting, consider combining it with other tools.","message":"DjHTML is an *indenter*, not a full *formatter*. It will only add or remove whitespace at the beginning of lines to correct indentation; it will not insert newlines, reorder attributes, or fix malformed HTML. Its goal is to correctly indent already well-structured templates.","severity":"gotcha","affected_versions":"All versions"},{"fix":"After a `pre-commit` failure due to DjHTML, stage the changes (`git add .`) and commit again. Alternatively, skip the hook if the changes are undesired or for a temporary bypass.","message":"When used as a `pre-commit` hook, if DjHTML modifies files, `git commit` will fail. You must `git add` the changes and re-commit, or use `SKIP=djhtml git commit` to bypass the hook for that commit.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}