☰ Menu
CLI Open source 10 installs/mo

djhtml for Mac

djhtml

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

  1. Open Terminal (press ⌘ + Space and type “Terminal”).
  2. If Homebrew is not installed yet, run the command below first.
  3. Run this command:

Latest 10 releases

Last updated 2026-03-26; current version 3.0.11, with the latest 10 releases listed.

VersionReleasedTypeSizemacOSWindowsLinux
3.0.112026-03-26Stable————
3.0.102025-10-08Stable————
3.0.92025-08-12Stable————
3.0.82025-05-22Stable————
3.0.72024-10-17Stable————
3.0.62023-03-16Stable————
3.0.52023-03-09Stable————
3.0.42023-03-07Stable————
3.0.32023-03-04Stable————
3.0.22023-02-24Stable————

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.

Compared with similar apps
AppVersionLicenseArchitecture30-day installs
djhtml3.0.11GPL-3.0-or-laterCLI10
blogcv0.20.1BSD-3-ClauseCLI16
ctemplatectemplate-2.4BSD-3-ClauseCLI9
stencil3.0.3Apache-2.0CLI26

Similar apps: Command-line Tools

Leave a comment

评论表单加载中…