Django Tailwind

4.4.2 · active · verified Thu Apr 16

The django-tailwind library integrates the Tailwind CSS framework seamlessly into Django projects. It provides management commands to install, build, and serve Tailwind CSS, streamlining frontend development within a Django context. It is actively maintained with frequent releases, currently at version 4.4.2.

Common errors

Warnings

Install

Imports

Quickstart

To quickly get started, add `django_tailwind` and your designated Tailwind app (e.g., 'theme') to `INSTALLED_APPS`, define `TAILWIND_APP_NAME`, include `django_tailwind.urls` in your project's `urls.py`, and use `{% tailwind_css %}` in your base template. Then, run `python manage.py tailwind install` to set up Node.js dependencies and `python manage.py tailwind start` for development.

# settings.py
INSTALLED_APPS = [
    # ... your other apps
    'django_tailwind',
    'theme', # Your Tailwind app name
]

TAILWIND_APP_NAME = 'theme'

# urls.py (your project's main urls.py)
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('django_tailwind.urls')),
    # ... your other url patterns
]

# Your Tailwind app (e.g., 'theme/apps.py')
# Make sure to define your Tailwind app as a Django app
# For example:
# from django.apps import AppConfig
# class ThemeConfig(AppConfig):
#     default_auto_field = 'django.db.models.BigAutoField'
#     name = 'theme'

# In your base template (e.g., templates/base.html)
# Make sure to create a templates directory in your 'theme' app
# and an input.css in 'theme/static_src/input.css'
# {% load tailwind_tags %}
# <head>
#     <title>My Django Tailwind App</title>
#     {% tailwind_css %}
# </head>
# <body>
#     <h1 class="text-3xl font-bold underline">Hello Tailwind!</h1>
# </body>

# Terminal commands
# python manage.py tailwind install
# python manage.py tailwind start
# (Open browser to your Django app, check console for Tailwind CSS build output)

view raw JSON →