DjHTML: Django/Jinja Template Indenter

3.0.11 · active · verified Wed Apr 15

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.

Warnings

Install

Quickstart

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

view raw JSON →