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)
| 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
|