Skip to main content

DjHTML

A pure-Python Django template indenter without any dependencies.

Installation

Install DjHTML with the following command:

$ pip install djhtml

Usage

After installation you can indent Django templates using the djhtml command. It has the following options:

$ djhtml --help
usage: djhtml [-h] [-i] [-q] [-t N] [-o filename] [filenames ...]

DjHTML is a Django template indenter that works with mixed
HTML/CSS/Javascript templates. It works similar to other code-
formatting tools such as Black. The goal is to correctly indent
already well-structured templates but not to fix broken ones. A
non-zero exit status indicates that a template could not be
indented.

positional arguments:
  filenames             input filenames

optional arguments:
  -h, --help            show this help message and exit
  -i, --in-place        modify files in-place
  -q, --quiet           be quiet
  -t N, --tabwidth N    tab width
  -o filename, --output-file filename
                        output filename

Pre-commit configuration

Even better, you can use DjHTML as a pre-commit hook to automatically indent your Django templates upon each commit.

First, add the following to your .pre-commit-config.yaml:

repos:
- repo: https://github.com/rtts/djhtml
  rev: main
  hooks:
  - id: djhtml

Then, run the following command:

$ pre-commit autoupdate

Results

Before:

{% block extrahead %}
<script>
function f() {
return 42;
}
</script>
{% endblock %}

After:

{% block extrahead %}
    <script>
        function f() {
            return 42;
        }
    </script>
{% endblock %}

Metadata

Release files for djhtml 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for djhtml 1.0.1
File Size Uploaded
djhtml-1.0.1.tar.gz 6.3 kB Details

Release files / djhtml-1.0.1.tar.gz

Download URL djhtml-1.0.1.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
cbcbc07468e4156ee27a23fe3f4e83e608611cb7e1646d9ea6facb542ed198b0
BLAKE2b-256 checksum
How to use checksums
8aa6a4c9e3abd4e19bcf08394eaed75df7a37f9ee53c7b921f9847d9922b2cb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

Release history Release notifications | RSS feed

3.0.11

2 release files

3.0.9

2 release files

3.0.8

1 release file

3.0.7

1 release file

3.0.6

1 release file

3.0.5

1 release file

3.0.4

1 release file

3.0.3

1 release file

3.0.2

1 release file

3.0.1

1 release file

3.0.0

1 release file

2.0.0

1 release file

1.5.2

1 release file

1.5.1

1 release file

1.5.0

1 release file

1.4.14

1 release file

1.4.13

1 release file

1.4.12

1 release file

1.4.11

1 release file

1.4.10

1 release file

1.4.9

1 release file

1.4.8

1 release file

1.4.7

1 release file

1.4.6

1 release file

1.4.5

1 release file

1.4.4

1 release file

1.4.3

1 release file

1.4.2

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.0

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.0.2

1 release file

This release

1.0.1 This release

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page