liveBook · Manning

MEDIA_ROOT

As explained in Django in Action

MEDIA_ROOT is a Django setting defining the filesystem directory where user-uploaded media files are stored.

MEDIA_ROOT defines the filesystem directory where Django stores user-uploaded files. Think of MEDIA_URL as the public address and MEDIA_ROOT as the files’ actual home on the server. section 7.4.1 section 7.6

.
├── RiffMates  #1
│   ├── RiffMates
│   │   ├── settings.py
│   │   ├── urls.py
│   │   └── wsgi.py
│   ├── db.sqlite3
│   ├── manage.py
│   └── static  #2
│       └── img
│           └── logo.png
├── BeatBosses  #3
│   ├── BeatBosses
│   │   ├── settings.py
│   │   ├── urls.py
│   │   └── wsgi.py
│   └── manage.py
└── outside  #4
    ├── RiffMates #5
    │   └── uploads  #6
    └── BeatBosses  #7
        └── uploads

Place uploads outside the project directory when desired, using a separate folder for each project; MEDIA_ROOT points to the relevant uploads directory. section 7.4.1

Configure RiffMates uploads

In settings.py, set MEDIA_ROOT to the server path containing uploaded files: MEDIA_ROOT = BASE_DIR.parent / 'outside/RiffMates/uploads'. Pair it with MEDIA_URL = '/media/'. During development, urls.py can serve that directory when DEBUG is true: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT). This development shortcut is not a production web-server arrangement. section 7.4.1

Keep these upload details in view:

  • Files under MEDIA_URL are publicly downloadable unless access is deliberately restricted. section 7.4.4
  • Restricted files belong outside MEDIA_ROOT and outside the publicly served /media/ path; custom views, web-server handoffs, or libraries can control access. section 7.4.4
  • Upload forms require multipart/form-data, and views handling ModelForms must pass request.FILES alongside request.POST. section 7.6

How Django in Action covers it

How deep it goes
Defines the filesystem role, demonstrates settings and development serving, but defers deeper upload implementation and production serving.
Examples
Uses the RiffMates uploads directory, settings.py configuration, and DEBUG-only URL patterns for development access.
What it assumes
Assumes basic Django settings and URL configuration while introducing upload storage, public media paths, and request file handling.
What you can do after
Operate/configure Django upload storage and development access while recognizing when public media handling is unsafe.
How it connects
Connects uploaded files with MEDIA_URL, FileField, ImageField, ModelForm, request.FILES, DEBUG, and web-server file serving.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.