Format your Django Templates easily with djLint
Sep 8, 2023
- Install Djlint locally with this command:
python -m pip install -U djlint
If this code doesn’t work, try with:
python3 -m pip install -U djlint
Remember, you previously should have installed python3 and pip
2. Install the Djlint extension in vscode:
3. Create a .vscode
folder in the root of your project, and inside this folder a file named settings.json
:
4. Add this code in the settings.json
file:
{
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"[html][django-html][handlebars][hbs][mustache][jinja][jinja-html][nj][njk][nunjucks][twig]": {
"editor.defaultFormatter": "monosans.djlint"
}
}
If you see the code, I’m using autopep8
to format my python code. You can easily install the extesion in vscode. If you use another formatter, you can just delete this line from the settings.json
file.