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
