Explain the conceptual difference between STATIC_URL and MEDIA_URL. Why should you never serve these files using the Django application server in production?
Last updated
Both are URL prefixes, but they serve different file categories: STATIC_URL is for developer-shipped assets (CSS, JS, images), while MEDIA_URL is for user-uploaded files. Neither should be served by the Django app server in production because that wastes the worker on slow file I/O a web server does far better.
STATIC_URL: Files you author and version-control;collectstaticgathers them intoSTATIC_ROOTfor deployment.MEDIA_URL: Runtime user uploads stored underMEDIA_ROOT; unpredictable and untrusted, so often need access control.Why not serve via Django in production:
Each file blocks a WSGI/ASGI worker that should be handling dynamic requests.
Web servers (Nginx) or a CDN/object store (S3) handle caching, range requests, and concurrency far more efficiently.
Django's
static()helper only works whenDEBUGis on, by design.