Registry / testing / djhtml

djhtml

JSON →
library3.0.11pypypiunverified

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.

pip install djhtml
INSTALL
IMPORT
SIG · DJHTML
D
djhtml
testingpythonv3.0.11
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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.

mkdir djhtml_test cd djhtml_test echo '{% if user.is_authenticated %}<div class="welcome">Hello, {{ user.username }}!</div>{% else %}<a href="/login/">Login</a>{% endif %}' > template.html # Indent a single file djhtml template.html # Verify changes cat template.html # Indent all HTML files in the current directory and subdirectories djhtml . # Example of checking without modifying (exit code 1 if changes are needed) djhtml --check template.html
djhtml --version
Debug
Known issues
breakingSupport 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.
fix
Upgrade Python to 3.9 or newer (e.g., `pyenv install 3.9.19 && pyenv local 3.9.19`).
affects: >=3.0.7
breakingThe `-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.
fix
Remove the `-q` or `--quiet` flag from your commands. For quiet output, redirect `stderr` (e.g., `djhtml template.html 2>/dev/null`).
affects: >=3.0.3
gotchaOn Windows, DjHTML highly advises setting the `PYTHONUTF8` environment variable to 1 to ensure correct handling of UTF-8 encoding, especially with legacy code pages.
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.
affects: All versions
gotchaDjHTML 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.
fix
Understand its scope: ensure your HTML is structurally sound before running DjHTML. For full formatting, consider combining it with other tools.
affects: All versions
gotchaWhen 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.
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.
affects: All versions
Errors
Common errors & fixes
djhtml: command not found
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.
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).
Failed - hook id: djhtml - files were modified by this hook
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.
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.
How to use djhtml on multiple files / indent an entire directory
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.
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`.
djhtml set tabwidth / djhtml --tabwidth not working
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.
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`.
Upgrade
Version history
3.0.11latest on PyPI · released Mar 26, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
djhtml — pip install djhtml · libregistry