Visual Studio Code extension for formatting and linting HTML templates (Django, Jinja, Nunjucks, Twig, Handlebars, Mustache) using djLint.
- Install djLint itself with the
pip install -U djlintcommand. - Install djLint VS Code extension from Visual Studio Marketplace or Open VSX.
If you have the Python extension installed, djlint-vscode will use the djLint installed in the currently activated Python environment, unless you have the djlint.useVenv extension setting disabled.
The extension can be configured through the settings in VS Code. Some options can be configured through the djLint configuration file.
Add this to your settings.json to format the default enabled languages with djLint:
"[html][django-html][handlebars][hbs][mustache][jinja][jinja-html][nj][njk][nunjucks][twig]": {
"editor.defaultFormatter": "monosans.djlint"
}pipx creates a separate venv for each application. You can see where it creates the venv with the pipx environment --value PIPX_LOCAL_VENVS command. For me it is /home/user/.local/share/pipx/venvs. This way I can set these settings:
"djlint.useVenv": false,
"djlint.pythonPath": "/home/user/.local/share/pipx/venvs/djlint/bin/python",uv creates a separate venv for each application. You can see where it creates the venv with the uv tool dir command. For me it is /home/user/.local/share/share/uv/tools. This way I can set these settings:
"djlint.useVenv": false,
"djlint.pythonPath": "/home/user/.local/share/share/uv/tools/djlint/bin/python",-
Non-ASCII characters turn into
?on Windows after formatting. To fix this, updatedjLintto v1.1.1 or higher. -
Linting does not work on Windows if the file contains non-ASCII characters. To fix this, update
djLintto v1.1.1 or higher. -
File contents are duplicated after formatting. This is a bug in
djLintv1.12.1, install another version. -
The config file is ignored on some versions of Python if it is in the root of the project. To fix this, update
djLintto v1.19.2 or higher.