{"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":"python","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,"search_vec":"'3.0.11':67 'act':35 'activ':55 'adjust':40 'black':33 'cadenc':61 'cli':72 'code':51 'commit':75 'comprehens':50 'consist':45 'depend':16 'django':24,70 'django/jinja':2,11 'djhtml':1,5,34 'ensur':44 'extern':15 'format':18,68 'html':69 'html/css/javascript':20 'incorpor':23 'indent':4,13,38,46 'jinja':26,71 'latest':64 'lead':41 'like':32 'maintain':56 'mix':19 'perform':49 'pre':74 'pre-commit':73 'primarili':39 'pure':9 'pure-python':8 'python':10 'rather':47 'reformat':52 'regular':59 'releas':60 'similar':29 'tag':28 'templat':3,12,21,27 'tool':31 'version':65 'whitespac':42 'without':14","created_at":"2026-04-15T05:33:16.275227+00:00","updated_at":"2026-04-16T14:37:48.653216+00:00","problems":[{"fix":"Activate your Python virtual environment if you are using one. If 'djhtml' is not installed, run `pip install djhtml`. Ensure your system's PATH includes the directory where Python installs scripts (e.g., `~/.local/bin` or a virtual environment's `bin` directory).","cause":"The 'djhtml' executable is not found in your system's PATH, often because a Python virtual environment where it was installed is not active, or the installation directory for Python scripts is not included in the PATH.","error":"djhtml: command not found"},{"fix":"Stage the files that `djhtml` modified using `git add .` (or `git add <file>`) and then commit again. `djhtml` has successfully done its job by re-indenting the files.","cause":"This message from `pre-commit` indicates that `djhtml` successfully re-indented one or more files in your working directory. `pre-commit` treats any modification to staged files by a hook as a 'failure' because it means the files were not correctly formatted before being staged.","error":"Failed - hook id: djhtml - files were modified by this hook"},{"fix":"To indent all `.html` files in the current directory and its subdirectories, use a command combining `find` and `xargs`: `find . -name '*.html' | xargs djhtml`.","cause":"By default, `djhtml` processes single files specified as arguments, or all HTML files in the current directory when using `djhtml .`. To apply it recursively to specific file types across multiple subdirectories, it needs to be combined with other shell commands.","error":"How to use djhtml on multiple files / indent an entire directory"},{"fix":"To set the tab width for a single run, use `djhtml --tabwidth N <file_or_directory>`, e.g., `djhtml --tabwidth 2 template.html`. When using `djhtml` as a `pre-commit` hook, specify the tab width in your `.pre-commit-config.yaml` under the hook's entry, for example: `entry: djhtml --tabwidth 2`.","cause":"Users may be unaware of the correct command-line argument to specify the tab width, or how to pass arguments to `djhtml` when it's configured as a `pre-commit` hook.","error":"djhtml set tabwidth / djhtml --tabwidth not working"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"djhtml","cli_version":"3.0.11","type":"library","homepage":"https://djhtml.readthedocs.io","github":"https://github.com/rtts/djhtml","docs":null,"changelog":null,"pypi":"https://pypi.org/project/djhtml/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-04-15","next_check":"2026-07-14","install_tag":null}}