djade

raw JSON →
1.9.0 verified Fri May 01 auth: no python

A Django template formatter that ensures consistent formatting of Django templates. It supports Jinja2-style templates with Django tags and filters, and is designed to be fast and configurable. Current version is 1.9.0, released with regular updates.

pip install djade
error ModuleNotFoundError: No module named 'djade'
cause djade is not installed in the current Python environment.
fix
Run pip install djade.
error django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
cause Djade tries to configure Django settings when parsing templates with custom template tags, but no settings are configured.
fix
Set the DJANGO_SETTINGS_MODULE environment variable or configure Django settings manually before using djade.
gotcha djade only supports Django templates, not Jinja2 templates. Attempting to use it with Jinja2 may produce incorrect results or raise errors.
fix Use a Jinja2-specific formatter like `djlint` for Jinja2 templates.
gotcha djade relies on the `DJANGO_SETTINGS_MODULE` environment variable to be set when processing templates that use template tags from third-party apps. If not set, it may fail to resolve custom template tags.
fix Set the environment variable or configure settings via `--settings` option if using CLI; in code, set `os.environ['DJANGO_SETTINGS_MODULE']` before using djade.
breaking In version 1.0, the API changed from `djade.format_code()` to `Djade().format()`. Old code will break.
fix Use `from djade import Djade; formatter = Djade(); formatted = formatter.format(source)` instead of `djade.format_code(source)`.

Basic usage of djade to format a Django template string.

from djade import Djade
import os

# Simple usage: format a template string
formatter = Djade()
template = """{% load static %}
<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
</head>
<body>
    <h1>Hello</h1>
</body>
</html>"""
formatted = formatter.format(template)
print(formatted)