Skip to content

Settings

djangofmt reads its configuration from the [tool.djangofmt] table of the closest pyproject.toml; command-line arguments take precedence over it.

Top-level

Options shared by the formatter (djangofmt) and the linter (djangofmt check).

line-length

The line length the formatter should fit code into when possible.

Default value: 120

Type: int

Example usage:

[tool.djangofmt]
line-length = 88

indent-width

The number of spaces per indentation level.

Default value: 4

Type: int

Example usage:

[tool.djangofmt]
indent-width = 2

profile

The template language to parse. Defaults to the file extension when unset (.html is Django, .jinja/.jinja2/.j2 are Jinja).

Default value: "django"

Type: "django" | "jinja"

Example usage:

[tool.djangofmt]
profile = "jinja"

custom-blocks

Names of custom block tags to treat as paired blocks, so their content is indented instead of left untouched.

Default value: []

Type: list[str]

Example usage:

[tool.djangofmt]
custom-blocks = ["cache", "spaceless"]

html-void-self-closing

Whether void HTML elements are written self-closing (<br />) or not (<br>). unchanged keeps whatever the source uses.

Default value: "never"

Type: "never" | "always" | "unchanged"

Example usage:

[tool.djangofmt]
html-void-self-closing = "always"

preserve-unquoted-attrs

Whether to leave unquoted attribute values (e.g. prop=True) as-is instead of quoting them. Useful for template syntaxes that assign non-string values through attributes.

Default value: false

Type: bool

Example usage:

[tool.djangofmt]
preserve-unquoted-attrs = true

exclude

File and directory patterns to exclude from discovery, replacing the default excludes.

A pattern without / (e.g. node_modules) excludes any file or directory with that name at any depth; a pattern with / (e.g. templates/vendor) is a glob anchored at the project root (the pyproject.toml directory), where * also crosses /.

Default value: [".bzr", ".direnv", ".eggs", ".git", ".git-rewrite", ".hg", ".mypy_cache", ".nox", ".pants.d", ".pytype", ".ruff_cache", ".svn", ".tox", ".venv", "__pypackages__", "_build", "buck-out", "dist", "node_modules", "venv"]

Type: list[str]

Example usage:

[tool.djangofmt]
exclude = ["generated"]

extend-exclude

File and directory patterns to exclude in addition to the default excludes.

Default value: []

Type: list[str]

Example usage:

[tool.djangofmt]
extend-exclude = ["templates/vendor"]

include

File patterns to format and lint, replacing the default includes.

Globs are anchored at the project root like exclude and matched against a file's full path, where * also crosses / (so *.html matches at any depth).

Default value: ["*.html", "*.jinja", "*.jinja2", "*.j2"]

Type: list[str]

Example usage:

[tool.djangofmt]
include = ["*.html"]

extend-include

File patterns to format and lint in addition to the default includes.

Default value: []

Type: list[str]

Example usage:

[tool.djangofmt]
extend-include = ["*.djhtml"]

respect-gitignore

Whether to skip files ignored by .gitignore, .ignore and friends when discovering files.

Default value: true

Type: bool

Example usage:

[tool.djangofmt]
respect-gitignore = false

force-exclude

Whether to apply exclude patterns to files passed on the command line too. Useful when running under pre-commit, which passes every changed file explicitly.

Default value: false

Type: bool

Example usage:

[tool.djangofmt]
force-exclude = true

lint

Options for the check command.

select

Rules and categories to enable, e.g. category:all, category:correctness or a rule name. category:default is every category except pedantic.

Default value: ["category:default"]

Type: list[RuleSelector]

Example usage:

[tool.djangofmt.lint]
select = ["category:default", "unsorted-tailwind-classes"]

ignore

Rules and categories to disable. A more specific selector always wins, regardless of order.

Default value: []

Type: list[RuleSelector]

Example usage:

[tool.djangofmt.lint]
ignore = ["category:style"]

preview

Whether to enable rules that are still in preview.

Default value: false

Type: bool

Example usage:

[tool.djangofmt.lint]
preview = true

target-version

The Django version the templates target, as a major.minor string.

When unset, it comes from the minimum supported Django version in [project] dependencies. Rules that depend on it stay disabled until it is known.

Default value: null

Type: str

Example usage:

[tool.djangofmt.lint]
target-version = "5.2"

fix

Whether to apply safe fixes automatically.

Default value: false

Type: bool

Example usage:

[tool.djangofmt.lint]
fix = true

unsafe-fixes

Whether to include unsafe fixes when applying with fix. Without fix, diagnostics from unsafe fixes are still reported as fixable.

Default value: false

Type: bool

Example usage:

[tool.djangofmt.lint]
unsafe-fixes = true

show-fixes

Whether to list per-rule fix counts after applying fixes.

Default value: false

Type: bool

Example usage:

[tool.djangofmt.lint]
show-fixes = true

output-format

How diagnostics are rendered.

Default value: "full"

Type: "full" | "concise"

Example usage:

[tool.djangofmt.lint]
output-format = "concise"

per-file-ignores

Rules to disable for files matching a glob pattern, relative to the pyproject.toml directory.

Default value: {}

Type: dict[str, list[RuleSelector]]

Example usage:

[tool.djangofmt.lint.per-file-ignores]
"templates/admin/*.html" = ["missing-img-alt"]

lint.unsorted-tailwind-classes

Options for the unsorted-tailwind-classes rule.

prefix

The Tailwind prefix your utilities are configured with. Without it, prefixed utilities are treated as unknown classes and left unsorted.

Default value: null

Type: str

Example usage:

[tool.djangofmt.lint.unsorted-tailwind-classes]
prefix = "tw-"  # Tailwind v3; use "tw:" for v4