I have installed the djLint extension in VS Code and updated my settings file.
...
"[html][django-html][handlebars][hbs][mustache][jinja][jinja-html][nj][njk][nunjucks][twig]": {
"editor.defaultFormatter": "monosans.djlint"
},
"[django-html]": {
"editor.defaultFormatter": "monosans.djlint",
"editor.detectIndentation": true,
"editor.formatOnSave": true,
"editor.tabSize": 4,
"djlint.profile": "django" // This will apply your custom profile
},
...
However, when I create a new directory and set up a virtual environment (.venv), I get the following error when trying to save a Django template:
djLint is not installed for the current active Python interpreter. Install it with the `c:\Test\Django\Test\.venv\Scripts\python -m pip install -U djlint` command.
I want to avoid manually installing djLint in every virtual environment. Would appreciate any solutions or best practices. Thanks!
After exploring the djLint VS Code extension repository, I found a way to make djLint
available across all virtual environments without manually installing it in each one.
uv
to Install djLint
GloballyInstead of installing djLint
in every virtual environment, I use uv
, which is a faster and more efficient package manager. Here's how to set it up:
djLint
using uv
uv tool install djlint
settings.json
in VS CodeModify your VS Code settings.json
file to disable virtual environment dependency and specify the correct Python path:
{
"djlint.useVenv": false,
// Linux Path
"djlint.pythonPath": "/home/user/.local/share/uv/tools/djlint/bin/python"
// Windows Path
"djlint.pythonPath":"C:\\Users\\SRJ\\AppData\\Roaming\\uv\\tools\\djlint\\Scripts\\python"
}
If anyone has a better approach, feel free to share!