Static Files
Overview¶
SpeedPy uses WhiteNoise for serving static files and Tailwind CSS for styling. Media files are served via an Nginx container in development.
WhiteNoise¶
WhiteNoise serves static files directly from the Django application, eliminating the need for a separate web server for static assets.
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
...
]
WHITENOISE_USE_FINDERS = True
WHITENOISE_AUTOREFRESH = DEBUG # Auto-refresh in development
Static File Settings¶
STATIC_URL = env.str("STATIC_URL", default="/static/")
STATIC_ROOT = env.str("STATIC_ROOT", default=BASE_DIR / "staticfiles")
STATICFILES_DIRS = [
BASE_DIR / "static",
]
Tailwind CSS¶
Tailwind is configured in tailwind.config.js with dark mode support, custom color themes, and several plugins.
Building CSS¶
# One-time build
docker compose run --rm web npm run tailwind:build
# Watch mode (rebuilds on changes)
docker compose run --rm web npm run tailwind:watch
Tailwind compiles from static/mainapp/input.css to static/mainapp/styles.css.
SpeedPy UI component classes live in static/mainapp/input.css inside Tailwind's @layer components; use those reusable classes in templates instead of repeating long utility strings.
Tailwind Directories¶
SpeedPy includes a generate_tailwind_directories management command that creates a tailwind_directories.json file. This file lists the template and static directories of installed Django apps (for example allauth and DRF) for Tailwind's content scanner to check for class names.
The file contains absolute paths for the machine it was made on, so it is not in Git (.gitignore). init-local.sh and init-docker.sh create it, and the Appliku build command creates it before npm run tailwind:build. Run it again after you add or remove a Django app or change the Python version:
docker compose run --rm web python manage.py generate_tailwind_directories
# local mode
uv run python manage.py generate_tailwind_directories
Plugins¶
Tailwind is configured with:
- @tailwindcss/forms — form element styling
- @tailwindcss/typography — prose typography
Media Files¶
Media files (user uploads like team logos) are stored in the media/ directory and served via an Nginx container in development:
media:
image: nginx
volumes:
- ./media:/usr/share/nginx/html
ports:
- "127.0.0.1:${MEDIA_PORT:-9001}:80"
init-docker.sh picks random WEB_PORT and MEDIA_PORT values and writes them to .env, so several SpeedPy projects can run side by side.
MEDIA_ROOT = env("MEDIA_ROOT", default=BASE_DIR / "media")
MEDIA_URL = normalize_media_url(env.str("MEDIA_URL", default=""))
In production, configure your web server or CDN to serve the media directory — or move media to object storage entirely.
See Media Storage for the full picture: platform volumes,
switching to any S3-compatible provider with USE_S3, and serving private files.
Collecting Static Files¶
For production deployment, collect static files into STATIC_ROOT:
WhiteNoise will serve these files with proper caching headers.