Static vs Media Files (Django)

In Django, static files are assets you ship with your code (CSS, JS, images), served under STATIC_URL; media files are user-uploaded content (avatars, documents) stored under MEDIA_ROOT and served under MEDIA_URL.

Django

The distinction matters because the two have different lifecycles. Static files are part of your project, version-controlled, and collected for deployment with collectstatic into STATIC_ROOT, then served by the web server or a CDN. You reference them in templates with {% load static %} and {% static 'css/app.css' %}.

Media files are created at runtime by users uploading content. A model's FileField or ImageField stores them under MEDIA_ROOT on disk (or in cloud storage), and they are served from MEDIA_URL. They are not committed to source control and need backups since they hold user data.

A common deployment mistake is conflating them or forgetting to run collectstatic, which leaves CSS/JS missing in production. In development Django can serve both, but in production a real web server or object storage handles them.

Syntax

STATIC_URL = "/static/"
MEDIA_URL = "/media/"

Examples

Python

# settings.py
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles"   # collectstatic target
MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "media"          # user uploads

# model
# avatar = models.ImageField(upload_to="avatars/")

Learn it in a lesson

See also

Back to the Dictionary