How to use all features of TailwindCSS in a Django project (not only the CDN), including a clean workflow with auto-reloading, and purgeCSS step to be production-ready?
W
Django-Tailwind CSS is a very good package and it works well for me. Follow the docs properly and you will be fine.
Before you begin, make sure you have npm
properly installed on your system
pip install django-tailwind
Alternatively, you can download or clone this repo and run pip install -e ..
Add tailwind
to INSTALLED_APPS in settings.py
Create a tailwind-compatible Django-app, I like to call it theme
:
python manage.py tailwind init theme
Add your newly created theme
app to INSTALLED_APPS in settings.py
In settings.py, register tailwind app by adding the following string:
TAILWIND_APP_NAME = 'theme'
python manage.py tailwind install
python manage.py tailwind start
Django Tailwind comes with a simple base.html template that can be found under yourtailwindappname/templates/base.html. You can always extend it or delete it if you have own layout.
If you're not using base.html template provided with Django Tailwind, add styles.min.css to your own base.html template file:
You should now be able to use Tailwind CSS classes in your html.
To build a production version of CSS run:
python manage.py tailwind build
For the live reload, this handles it:
python manage.py tailwind start
For the build process, this handles it:
python manage.py tailwind build
For the PurgeCSS process, see simple sample in the docs
For NPM path configuration error (esp. on windows), see docs