Automatic formatting of Django templates

I found that you can use comments to have prettier ignore your tags

My observations:

I was so desperate that I wanted to write a prettier plugin, but luckily I have found a working one (with exactly zero stars) - GitHub - sezze/prettier-plugin-django-alpine: Format Django tags and Alpine.js in HTML files.

For VSCode it requires extension & local installation of prettier - you may need to use "prettier.prettierPath": "./node_modules/prettier/index.cjs" in your settings.json (as newbie I am not allowed to add the 3rd link to this post).

4 Likes

I use TailwindCSS and need sorting of class names - it would be nice if it is done by prettier to. But the official plugin prettier-plugin-tailwindcss is crazy and whitelists (actually embeds) compatible (presumably popular) plugins. So I made a fork and now I can have support for it all: GitHub - brablc/prettier-plugin-tailwindcss-django-alpine: A Prettier plugin for Tailwind CSS that automatically sorts classes based on our recommended class order. .

1 Like

Thanks! FWIW, the performance issue with djlint was apparently fixed a couple of months ago.

I note your fork, prettier-plugin-tailwindcss-django-alpine, hasn’t had an update in about two years. Are you still using it, or would you recommend something else now?

Hi, I am using it all the time (eventhough I have switched from VSCode to Lazyvim) and I have upgraded it to Tailwind CSS on request from @eyalch just now.

1 Like