Allow MEDIA_ROOT inside STATIC_ROOT
|Reported by:||Bruno Renié||Owned by:|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
I have the following layout:
STATIC_ROOT = '/path/to/static/' STATIC_URL = '/static/' MEDIA_ROOT = STATIC_ROOT + 'media/' MEDIA_URL = STATIC_URL + 'media/'
Basically, MEDIA_ROOT is a subdirectory of STATIC_ROOT.
With runserver, I won't be able to serve my media files. When I try to fetch a media file, the StaticFilesHandler tries to handle it (since its URL starts with STATIC_URL) but no finder will be able to resolve its path.
The handler then raises a 404 even if I have a pattern in my urlconf to serve my media files.
After discussing it on IRC, it looks like two things are needed to support this:
- Patch the contrib.staticfiles handler to specifically ignore anything inside MEDIA_URL
- Add extra checks to the collectstatic management command to make sure collectstatic won't write anything inside MEDIA_ROOT (which could potentially overwrite some user data).