Consider the following setup:
urls.py
if not settings.PRODUCTION:
urlpatterns += patterns('',
(r'^admin-media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.LOCAL_ADMIN_MEDIA_ROOT, 'show_indexes': True}),
(r'^media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.LOCAL_MEDIA_ROOT, 'show_indexes': True}),
)
settings.py
if not PRODUCTION:
ADMIN_MEDIA_PREFIX = '/admin-media/'
So when running on the local development server the media files should be served through the runserver, right? The media route is found, however "Permission denied" is returned for every request (but only one admin media, the regular media works fine).
So I did some checking into it. It turns out, if the ADMIN_MEDIA_PREFIX
is set to the same value as the route...
(r'^admin-media/(?P<path>.*)$', 'django.views.static.serve', ... ),
ADMIN_MEDIA_PREFIX = '/admin-media/'
...then the runserver will always return "Permission denied."
However, if ADMIN_MEDIA_PREFIX
is different than the route name...
(r'^admin-media/(?P<path>.*)$', 'django.views.static.serve', ... ),
ADMIN_MEDIA_PREFIX = '/non-sense-prefix/'
... then the files will be served (though I have to manually browse to be able to see them as all the media links are broken with http://localhost:8000/non-sense-prefix/whatever.jpg).
What's the deal here?
In the mean time I've solved the problem by a little hack to change directories...
(r'^admin-media/(?P<path>.*)$', 'django.views.static.serve', ... ),
ADMIN_MEDIA_PREFIX = '/admin-media/../admin-media/'
...but I would really rather configure this properly. It seems django is trying to be smart and do something on my behalf, but messing things up in the process. Any ideas?
EDIT -- I'm manually serving the admin media because I'm using grappelli which provides replacement for the admin templates/media.