Configuration

Configuration is done either through your project’s pyproject.toml file, a djlint.toml or .djlint.toml file, or a .djlintrc file. Command line args will always override any settings in configuration files. Local project settings override a global configuration file given with --configuration, unless --prefer-configuration is set.

The format for pyproject.toml is toml.

[tool.djlint]
<config options>

The format for djlint.toml and .djlint.toml is toml.

<config options>

The format for .djlintrc is json.

{ "option": "value" }

Options


allow_empty_input

since 1.44.0formatterlinter

Exit with 0 instead of 2 when the given paths match no files at all. Files that were found and then skipped by exclude, extend_exclude, use_gitignore or require_pragma already exit with 0. Disabled by default.

allow_empty_input=true
allow_empty_input=true
"allow_empty_input": true
--allow-empty-input

blank_line_after_tag

since 0.4.2formatter

Add an additional blank line after {% <tag> ... %} tag groups. Blank lines will never be added to end of block.

blank_line_after_tag="load,extends,include"
blank_line_after_tag="load,extends,include"
"blank_line_after_tag": "load,extends,include"
--blank-line-after-tag "load,extends,include"

blank_line_before_tag

since 1.8.0formatter

Add an additional blank line before {% <tag> ... %} tag groups. Blank lines will never be added to start of file or block, or between similar tags.

blank_line_before_tag="load,extends,include"
blank_line_before_tag="load,extends,include"
"blank_line_before_tag": "load,extends,include"
--blank-line-before-tag "load,extends,include"

close_void_tags

since 1.26.0formatterlinter

Add a closing mark to known void tags, so that <img> becomes <img />. H018, which asks for the opposite, is not reported under it.

close_void_tags=true
close_void_tags=true
"close_void_tags": true
--close-void-tags

custom_blocks

since 0.3.5formatter

Names of custom template blocks to indent, such as toc for {% toc %}...{% endtoc %}.

custom_blocks="toc,example"
custom_blocks="toc,example"
"custom_blocks": "toc,example"
--custom-blocks "toc,example"

custom_html

since 0.7.0formatter

Names of custom HTML tags to indent, such as mjml or simple-greeting. A name can be a regex, as in mj-\w+.

custom_html="mjml,simple-greeting,mj-\\w+"
custom_html="mjml,simple-greeting,mj-\\w+"
"custom_html": "mjml,simple-greeting,mj-\\w+"
--custom-html "mjml,simple-greeting,mj-\\w+"

exclude

since 0.4.0linterformatter

Override the default exclude paths.

exclude=".venv,venv,.tox,.eggs,..."
exclude=".venv,venv,.tox,.eggs,..."
"exclude": ".venv,venv,.tox,.eggs,..."
--exclude ".venv,venv,.tox,.eggs,..."

extend_exclude

since 0.4.0linterformatter

Add additional paths to the default exclude.

extend_exclude=".custom"
extend_exclude=".custom"
"extend_exclude": ".custom"
--extend-exclude ".custom"

extension

since 0.0.5linterformatter

Extension of the files to look for in folders. Default is html.

extension="html.dj"
extension="html.dj"
"extension": "html.dj"
--extension "html.dj"
# or
-e "html.dj"

files

since 1.14.0linterformatter

A list of paths to use as djlint’s source. When this option is specified, the command line source must be - as if using stdin. --stdin-filename makes - mean stdin regardless.

[tool.djlint]
files=["index.html"]
files=["index.html"]
"files": [
    "index.html"
]
index.html

format_attribute_js_json

since 1.37.0formatter

Format JavaScript and JSON code inside HTML attributes. This will format object literals and JavaScript code in attributes like onclick, x-*, and other JavaScript-related attributes. Objects with fewer properties than format_attribute_js_json_min_props will not be formatted.

format_attribute_js_json=true
format_attribute_js_json=true
"format_attribute_js_json": true
--format-attribute-js-json

format_attribute_js_json_min_props

since 1.37.0formatter

Minimum number of properties required in a JavaScript/JSON object for it to be formatted. Default is 2. Objects with fewer properties will remain on a single line.

format_attribute_js_json_min_props=3
format_attribute_js_json_min_props=3
"format_attribute_js_json_min_props": 3
--format-attribute-js-json-min-props 3

format_attribute_js_json_pattern

since 1.37.0formatter

Custom regex pattern to match JavaScript attributes for formatting. Default pattern matches common JavaScript attributes like onclick, x-*, Vue.js directives, Alpine.js directives, Angular directives, and more.

format_attribute_js_json_pattern="^(on[a-z]+|data-[a-z-]+|x-[a-z-]+)$"
format_attribute_js_json_pattern="^(on[a-z]+|data-[a-z-]+|x-[a-z-]+)$"
"format_attribute_js_json_pattern": "^(on[a-z]+|data-[a-z-]+|x-[a-z-]+)$"
--format-attribute-js-json-pattern "^(on[a-z]+|data-[a-z-]+|x-[a-z-]+)$"

format_attribute_template_tags

since 0.6.7formatter

Format template syntax inside tag attributes. Disabled by default.

format_attribute_template_tags=true
format_attribute_template_tags=true
"format_attribute_template_tags": true
--format-attribute-template-tags

format_css

since 1.9.0formatter

Format contents of style tags using css-beautify. See css-beautify for all configuration options. Template syntax is not fully supported.

[tool.djlint]
format_css=true

[tool.djlint.css]
indent_size=5
format_css=true

[css]
indent_size=5
"format_css": true,
"css": {
        "indent_size": 5
    }
--format-css --indent-css 5

format_js

since 1.9.0formatter

Format contents of script tags using js-beautify. See js-beautify for all configuration options. Template syntax is not fully supported. A script whose type is neither JavaScript nor JSON, such as a client-side template in text/template, is left as written.

[tool.djlint]
format_js=true

[tool.djlint.js]
indent_size=5
format_js=true

[js]
indent_size=5
"format_js": true,
"js": {
        "indent_size": 5
    }
--format-js --indent-js 5

ignore

since 0.1.5linter

Linter codes to skip.

ignore="H014,H015"
ignore="H014,H015"
"ignore": "H014,H015"
--ignore "H014,H015"

ignore_blocks

since 1.24.0formatter

Template blocks that do not indent their contents. Their children are treated as siblings of the block and indented accordingly.

ignore_blocks="raw,example"
ignore_blocks="raw,example"
"ignore_blocks": "raw,example"
--ignore-blocks "raw,example"

ignore_case

since 1.23.0formatterlinter

Do not attempt to fix the case of known html tags. H009 and H010 are not reported under it.

[tool.djlint]
ignore_case=true
ignore_case=true
"ignore_case": true
--ignore-case

include

since 1.20.0linter

Linter codes to turn on that are off by default.

include="H014,H015"
include="H014,H015"
"include": "H014,H015"
--include "H014,H015"

indent

since 0.3.5formatter

Spaces per indent level. Default is 4, or the indent_size of a .editorconfig at the project root.

indent=3
indent=3
"indent": 3
--indent 3

keep_br_inline

since 1.45.0formatter

Keep <br> on the line of the text it breaks, rather than giving it a line of its own. <hr>, which renders as a rule below the preceding content, is unaffected.

keep_br_inline=true
keep_br_inline=true
"keep_br_inline": true
--keep-br-inline

line_break_after_multiline_tag

since 1.27.0formatter

When a tag’s attributes are spread over lines, start its content on a new line.

line_break_after_multiline_tag=true
line_break_after_multiline_tag=true
"line_break_after_multiline_tag": true
--line-break-after-multiline-tag

linter_output_format

since 0.6.7linter

Customize the order of the output message. Default is “{code} {line} {message} {match}”. If {filename} is not in the message, the output is grouped by file and each group gets a header.

Optional variables:

  • {filename}
  • {line}
  • {end}
  • {code}
  • {message}
  • {match}
linter_output_format="{filename}:{line}: {code} {message} {match}"
linter_output_format="{filename}:{line}: {code} {message} {match}"
"linter_output_format": "{filename}:{line}: {code} {message} {match}"
--linter-output-format "{filename}:{line}: {code} {message} {match}"

max_attribute_length

since 0.5.8formatter

The formatter spreads a tag’s attributes over lines once they are longer than this. Default is 70.

max_attribute_length=10
max_attribute_length=10
"max_attribute_length": 10
--max-attribute-length 10

max_blank_lines

since 1.31.0formatter

Keep at most this many blank lines in a row. Default is 0, which removes blank lines. It has no effect with preserve_blank_lines.

max_blank_lines=5
max_blank_lines=5
"max_blank_lines": 5
--max-blank-lines 5

max_line_length

since 0.5.7formatter

The formatter joins some HTML and template tags onto one line only when the line fits within this length. Default is 120, or the max_line_length of a .editorconfig at the project root.

max_line_length=120
max_line_length=120
"max_line_length": 120
--max-line-length 120

name_endblocks

since 1.45.0formatter

Write the block’s name into the {% endblock %} that closes it, where the block is written across lines. This is what T003 asks for.

name_endblocks=true
name_endblocks=true
"name_endblocks": true
--name-endblocks

no_entity_formatting

since 1.45.0formatter

Do not rewrite an entity reference as the character it names, so &copy; is left as written rather than becoming ©. The entities that carry syntax, and the invisible ones, are never rewritten either way. H023 still reports an entity under it; add H023 to ignore to keep entities.

no_entity_formatting=true
no_entity_formatting=true
"no_entity_formatting": true
--no-entity-formatting

no_function_formatting

since 1.30.2formatter

Do not attempt to format the arguments of function calls inside {{ }} expressions.

no_function_formatting=true
no_function_formatting=true
"no_function_formatting": true
--no-function-formatting

no_indent_inner_html

since 1.45.0formatter

Do not indent <head> and <body> below <html>, which is how the default VS Code html formatter lays a document out.

no_indent_inner_html=true
no_indent_inner_html=true
"no_indent_inner_html": true
--no-indent-inner-html

no_line_after_yaml

since 1.29.0formatter

Do not add a blank line after YAML front matter.

no_line_after_yaml=true
no_line_after_yaml=true
"no_line_after_yaml": true
--no-line-after-yaml

no_set_formatting

since 1.30.2formatter

Do not attempt to format the contents of {% set %} tags.

no_set_formatting=true
no_set_formatting=true
"no_set_formatting": true
--no-set-formatting

per_file_ignores

since 1.7.0linter

Ignore linter rules on a per-file basis.

[tool.djlint.per-file-ignores]
"file.html"= "H026,H025"
"file_two.html"="H001"
[per-file-ignores]
"file.html"= "H026,H025"
"file_two.html"="H001"
"per-file-ignores": {
        "file.html": "H026,H025",
        "file_two.html":"H001"
    }
--per-file-ignores "file.html" "H026,H025" --per-file-ignores "file_two.html" "H001"

prefer_configuration

since 1.45.0formatterlinter

Let the file named by configuration override the project’s own config file. configuration names a global file, so by default a pyproject.toml or .djlintrc beside the templates wins where the two set the same thing. Command line only, since it decides how the config files themselves are read.

--prefer-configuration

preserve_blank_lines

since 1.3.0formatter

Preserve blank lines where possible. Ideal for non-html template files where blank lines are intentional.

preserve_blank_lines=true
preserve_blank_lines=true
"preserve_blank_lines": true
--preserve-blank-lines

preserve_class_newlines

since 1.39.0formatter

Preserve line breaks inside multiline class attributes.

preserve_class_newlines=true
preserve_class_newlines=true
"preserve_class_newlines": true
--preserve-class-newlines

preserve_leading_space

since 1.2.0formatter

Preserve leading space on text, where possible. Ideal for non-html template files where text indent is intentional.

preserve_leading_space=true
preserve_leading_space=true
"preserve_leading_space": true
--preserve-leading-space

profile

since 0.4.5linterformatter

Set a profile for the template language. The profile will enable linter rules that apply to your template language, and may also change reformatting. For example, in handlebars there are no spaces inside {{#if}} tags.

Options:

  • html (default)
  • django
  • jinja
  • nunjucks (for nunjucks and twig)
  • handlebars (for handlebars and mustache)
  • liquid (shopify, jekyll, eleventy)
  • golang (go templates; hugo, helm)
  • angular
  • tera (also for zola; use jinja for minijinja)
  • askama (jinja-style templates in rust; rust expressions are never reformatted)
  • mako (control lines and ## comments are kept as written)
  • all (every template language at once)
profile="django"
profile="django"
"profile": "django"
--profile "django"

quiet

since 0.0.9formatterlinter

Do not print diffs, the progress bar or the summary.

quiet=true
quiet=true
"quiet": true
--quiet

quote_style

since 1.45.0formatterlinter

Quotes to use for strings inside template tags, either double (the default) or single. T002 requires the same quotes. The formatter uses them in a condition too, such as {% if x == "a" %}, so one file does not spell the same string both ways. HTML attribute quoting is left to H008.

quote_style="single"
quote_style="single"
"quote_style": "single"
--quote-style single

require_pragma

since 0.5.8formatter

Only format or lint files that start with a comment with only the text ‘djlint:on’. The comment can be an HTML comment or a comment in the template language defined by the profile setting. If no profile is specified, a comment in any of the template languages is accepted.

<!-- djlint:on -->
{# djlint:on #}
{% comment %} djlint:on {% endcomment %}
{{ /* djlint:on */ }}
{{!-- djlint:on --}}
require_pragma=true
require_pragma=true
"require_pragma": true
--require-pragma

single_attribute_per_line

since 1.40.0formatter

When an opening tag wraps, put the tag name, each attribute, and the closing bracket on separate lines. Disabled by default.

single_attribute_per_line=true
single_attribute_per_line=true
"single_attribute_per_line": true
--single-attribute-per-line

sort_attributes

since 1.45.0formatter

Sort attributes by name, with id first and class second. A tag whose attributes are guarded by a template tag keeps the order it was written in, since moving one out of its branch would change the page.

sort_attributes=true
sort_attributes=true
"sort_attributes": true
--sort-attributes

sort_load_tags

since 1.47.0formatter

Sort the libraries in a django {% load %} tag and drop the ones written twice, so {% load static i18n %} becomes {% load i18n static %}. In {% load a b from library %} the names before from are sorted. Where two libraries define a tag or filter of the same name, the one loaded last wins, so sorting can change which one the template uses.

sort_load_tags=true
sort_load_tags=true
"sort_load_tags": true
--sort-load-tags

stdin_filename

since 1.43.0formatterlinter

Path that stands for stdin in messages and when matching excludes and per-file-ignores. Defaults to “-”.

--stdin-filename templates/index.html

use_gitignore

since 0.5.9linterformatter

Add .gitignore excludes to the default exclude. Disabled by default.

use_gitignore=true
use_gitignore=true
"use_gitignore": true
--use-gitignore

version

since 0.3.9formatterlinter

Show the version and exit.

--version

warn

since 0.7.6formatterlinter

Exit with 0 instead of 1 when there are lint errors or files to reformat.

--warn