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 djhtmlNo compatibility data collected yet for this library.
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.
Upgrade Python to 3.9 or newer (e.g., `pyenv install 3.9.19 && pyenv local 3.9.19`).
Remove the `-q` or `--quiet` flag from your commands. For quiet output, redirect `stderr` (e.g., `djhtml template.html 2>/dev/null`).
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.
Understand its scope: ensure your HTML is structurally sound before running DjHTML. For full formatting, consider combining it with other tools.
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.
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).
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.
To indent all `.html` files in the current directory and its subdirectories, use a command combining `find` and `xargs`: `find . -name '*.html' | xargs djhtml`.
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`.
No dependency data recorded yet.