Serving Media Files in Development

A snippet showing how to serve media files during development in Django.


# settings.py
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'

# urls.py
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
      
Explanation:
  • MEDIA_URL is used as base URL for media files.
  • MEDIA_ROOT defines where files are stored locally.
    • Category Static & Media Files
    • Total Views 324
    • Last Modified 09 May, 2026
    • Tags #media #development #files #django
    Never miss a story on Django.wiki

    Subscribe for fresh tutorials, snippets, and updates.

    By subscribing you agree to our Privacy Policy.