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 17 June 2026

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; collectstatic gathers them into STATIC_ROOT for deployment.

  • MEDIA_URL: Runtime user uploads stored under MEDIA_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 when DEBUG is on, by design.

  • https://dev.to/doridoro/django-difference-between-mediaroot-and-staticroot-5cb
  • https://www.geeksforgeeks.org/python/django-how-to-create-a-file-and-save-it-to-a-models-filefield/
All Django interview questions