Two tools, two jobs
Tailwind is utility CSS: you style elements with classes such as rounded px-4 py-2. crispy-forms is a Django app that renders forms as HTML. Together they replace hand-written CSS and the bare output of {{ form.as_p }}.
| Part | Question it answers |
|---|---|
| Tailwind | how do elements look |
| crispy-forms | what markup does a form produce |
crispy-tailwind | which Tailwind classes does that markup use |
Tailwind without Node
Tailwind v4 ships a standalone executable, so a Django project does not need npm. Create an input file:
/* static/src/input.css */
@import "tailwindcss";
@source "../../templates";
@source "../../blog";
@theme {
--color-brand: #2563eb;
}Run the binary (download it from the Tailwind GitHub releases):
# get the binary: tailwindlabs/tailwindcss releases
# development: rebuild on every change
./tailwindcss -i static/src/input.css -o static/css/app.css --watch
# production: one minified file
./tailwindcss -i static/src/input.css -o static/css/app.css --minifyConnect the result to Django:
# settings.py
STATIC_URL = "static/"
STATICFILES_DIRS = [BASE_DIR / "static"]{% load static %}
<link rel="stylesheet" href="{% static 'css/app.css' %}">