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_URLis 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
Previous snippet
Load Static Files in Templates
Next snippet