Chapter 11 of 12
Static files are your CSS, JavaScript, and images that don't change per user. Media files are uploaded content (user avatars, course thumbnails). Django handles both differently.
# settings.py
import os
# Static files (CSS, JS, images you ship with the code)
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles" # where collectstatic puts files for production
# Media files (user-uploaded content)
MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "media"
# During development โ serve media files via Django
# myproject/urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)# Copies all static files to STATIC_ROOT
python manage.py collectstatic
# Your web server (Nginx, etc.) then serves STATIC_ROOT directly