djhtml for Mac
A pure-Python Django/Jinja template indenter without dependencies.
djhtml — overview
A pure-Python Django/Jinja template indenter without dependencies.
DjHTML indents mixed HTML/CSS/JavaScript templates that contain
or Jinja template tags. It works similar to other code-formatting tools such as Black and interoperates nicely with pre-commit.
DjHTML is an _indenter_ and not a _formatter_: it will only add/remove whitespace at the beginning of lines. It will not insert newlines or other characters. The goal is to correctly indent already well-structured templates, not to fix broken ones.
If you are looking for an actual template _formatter_, check out the djangofmt project.
Installation
DjHTML requires Python 3.9 or higher and is compatible with all operating systems supported by Python. Install DjHTML with the following command:
$ pip install djhtml
Note that
instead of UTF-8. It is highly advised to set the environment variable PYTHONUTF8 to 1 with the
command:
C:> setx /m PYTHONUTF8 1
Usage
After installation you can indent templates using the djhtml command:
$ djhtml template.html reindented template.html 1 template has been reindented.
You can also run djhtml . to indent all HTML files beneath the current directory.
An exit status of 0 means that everything went well, regardless of whether any files were changed. When the option -c / --check is used, the exit status is 1 when one or more files would have changed, but no changes are actually made. All available options are given by djthml -h / djthml --help.
Command-line arguments
DjHTML supports the following command-line arguments: -h / --help: Show help text. -v / --version: Show version number. -c / --check: Dry-run, checks without modifying files. -t / --tabwidth N: Tabwidth. The default is to guess. -b / --extra-block BEGIN,END: Define an extra non-standard block tag. Can be used multiple times.
fmt:off and fmt:on
You can exclude specific lines from being processed with the {# fmt:off #} and {# fmt:on #} operators:
Contents inside ... , `, / ... /, and {% comment %} ... {% endcomment %} tags are also ignored (depending on the current mode).
Modes
The indenter operates in one of three different modes: DjHTML mode: the default mode. Invoked by using the djhtml command or the pre-commit hook. DjCSS mode. Will be entered when a tag is encountered in DjHTML mode. It can also be invoked directly with the command djcss. DjJS mode. Will be entered when a tag is encountered in DjHTML mode. It can also be invoked directly with the command djjs.
pre-commit configuration
A great way to use DjHTML is as a pre-commit hook, so all your HTML, CSS and JavaScript files will automatically be indented upon every commit.
First, install pre-commit:
$ pip install pre-commit $ pre-commit install
Then, add the following to your .pre-commit-config.yaml:
Now run pre-commit autoupdate to automatically replace main with the latest tag on GitHub, as recommended by pre-commit.
Details
Django/Jinja 模板缩进器
How to install djhtml
- Open Terminal (press ⌘ + Space and type “Terminal”).
- If Homebrew is not installed yet, run the command below first.
- Run this command:
Latest 10 releases
Last updated 2026-03-26; current version 3.0.11, with the latest 10 releases listed.
| Version | Released | Type | Size | macOS | Windows | Linux |
|---|---|---|---|---|---|---|
| 3.0.11 | 2026-03-26 | Stable | — | — | — | — |
| 3.0.10 | 2025-10-08 | Stable | — | — | — | — |
| 3.0.9 | 2025-08-12 | Stable | — | — | — | — |
| 3.0.8 | 2025-05-22 | Stable | — | — | — | — |
| 3.0.7 | 2024-10-17 | Stable | — | — | — | — |
| 3.0.6 | 2023-03-16 | Stable | — | — | — | — |
| 3.0.5 | 2023-03-09 | Stable | — | — | — | — |
| 3.0.4 | 2023-03-07 | Stable | — | — | — | — |
| 3.0.3 | 2023-03-04 | Stable | — | — | — | — |
| 3.0.2 | 2023-02-24 | Stable | — | — | — | — |
Data from GitHub Releases; stable releases first, each group sorted newest first.
Prebuilt bottle platforms
Official Homebrew bottles cover:
- all
⚠️ No prebuilt bottle for Intel Macs; Intel users need brew install --build-from-source to build from source.
Compared with similar apps
Only public metadata is compared, with no subjective recommendation; see the compare pages for field-by-field comparisons.
| App | Version | License | Architecture | 30-day installs |
|---|---|---|---|---|
| djhtml | 3.0.11 | GPL-3.0-or-later | CLI | 10 |
| blogc | v0.20.1 | BSD-3-Clause | CLI | 16 |
| ctemplate | ctemplate-2.4 | BSD-3-Clause | CLI | 9 |
| stencil | 3.0.3 | Apache-2.0 | CLI | 26 |
Similar apps: Command-line Tools
blogc
Blog compiler with template engine and markup languagectemplate
Welcome to the C++ CTemplate system!stencil
Stencil is a modern template engine for continuously evolving code repositories, used as a…inja
Template engine for modern C++openssl@4
Cryptography and SSL/TLS Toolkitxz
General-purpose data compression with high compression ratioCategories: Command-line Tools