Configuration

Configuration is done either through your projects pyproject.toml file, or a .djlintrc file. Command line args will always override any settings in pyproject.toml. Local project settings will always override global configuration files.

The format for pyproject.toml is toml.

[tool.djlint]
<config options>

The format for .djlintrc is json.

{
  "option": "value"
}

Options


blank_line_after_tag

formatter

Add an additional blank line after {% <tag> ... %} tag groups.

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

formatter

Add an additional blank line before {% <tag> ... %} tag groups. Blank lines will never be added to start of file 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"

close_void_tags

formatter

Close void tags.

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

custom_blocks

formatter

Use to indent custom code blocks. For example {% toc %}...{% endtoc %}

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

custom_html

formatter

Use to indent custom HTML tags. For example <mjml> or <simple-greeting> or <mj-\\w+>

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

exclude

linterformatter

Override the default exclude paths.

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

extend_exclude

linterformatter

Add additional paths to the default exclude.

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

extension

linterformatter

Use to only find files with a specific extension.

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

files

linterformatter

A list of paths to use as djlint’s source. When this option is specfied, the command line souce must be - as if using stdin.

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

format_attribute_template_tags

formatter

Formatter will attempt to format template syntax inside of tag attributes. Disabled by default.

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

format_css

formatter

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

[tool.djlint]
format_css=true

[tool.djlint.css]
indent_size=5
"format_css": true
"css": {
        "indent_size": 5
    }
--format-css --indent-css 5

format_js

formatter

Format contents of script tags using js-beautify. See js-beautify for all configuration options. Template syntax is not fully supported in supported.

[tool.djlint]
format_js=true

[tool.djlint.js]
indent_size=5
"format_js": true
"js": {
        "indent_size": 5
    }
--format-js --indent-js 5

ignore

linter

Ignore linter codes.

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

ignore_blocks

formatter

Used to skip indentation on children of template tags. Children will be treated as siblings and indented accordingly.

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

ignore_case

formatter

Do not attempt to fix the case of known html tags.

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

include

linter

Include linter codes.

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

indent

formatter

Use to change the code indentation. Default is 4 (four spaces).

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

line_break_after_multiline_tag

formatter

Do not condense the content of multi-line tags into the line of the last attribute.

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

linter_output_format

linter

Customize order of output message. Default=“{code} {line} {message} {match}”. If {filename} is not include in message, then the output will be grouped by file and a header will automatically be added to each group.

Optional variables:

  • {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

formatter

Formatter will attempt to wrap tag attributes if the attribute length exceeds this value.

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

max_blank_lines

formatter

Consolidate blank lines down to x lines. Default is 0 meaning blank lines will be removed.

max_blank_lines=5
"max_blank_lines": 5
--max_blank_lines 5

max_line_length

formatter

Formatter will attempt to put some html and template tags on a single line instead of wrapping them if the line length will not exceed this value.

max_line_length=120
"max_line_length": "120"
--max_line_length 120

no_function_formatting

formatter

Do not attempt to format function contents. ** If you use this option please open a gh issue explaining what caused you to use it.

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

no_line_after_yaml

formatter

Do not add a blank line after yaml front matter.

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

no_set_formatting

formatter

Do not attempt to format set contents. ** If you use this option please open a gh issue explaining what caused you to use it.

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

per_file_ignores

linter

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" --per-file-ignores "file_two.html" "H001"

preserve_blank_lines

formatter

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

preserve_blank_lines=true
"preserve_blank_lines": true
--preserve_blank_lines

preserve_leading_space

formatter

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

profile

linterformatter

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)
  • golang
  • angular

profile="django"
"profile": "django"
--profile "django"

quiet

formatterlinter

Do not print diff when reformatting.

--quiet

require_pragma

formatter

Only format or lint files that starts with a comment with only the text ‘djlint:on’. The comment can be a 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

use_gitignore

linterformatter

Add .gitignore excludes to the default exclude.

use_gitignore=true
"use_gitignore": true
--use_gitignore

version

formatterlinter

Show the version and exit.

--version

warn

formatterlinter

Return errors as warnings.

--warn
Edit this page Updated Dec 22, 2023