Local hosting administrator resources during development

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 launched on a local development server, media files must be served through servers, right? A media route was found, however, "Permission denied" is returned for each request (but only one administrator medium, normal media is working fine).

So, I checked something. It turns out that the ADMIN_MEDIA_PREFIX parameter ADMIN_MEDIA_PREFIX set to the same value as the route ...

 (r'^admin-media/(?P<path>.*)$', 'django.views.static.serve', ... ), ADMIN_MEDIA_PREFIX = '/admin-media/' 

... then the winning server will always return "Permission denied."

However, if ADMIN_MEDIA_PREFIX is different from the route name ...

 (r'^admin-media/(?P<path>.*)$', 'django.views.static.serve', ... ), ADMIN_MEDIA_PREFIX = '/non-sense-prefix/' 

... then the files will be served (although I have to manually look through them to see them, since all media links are broken into http: // localhost: 8000 / non-sense-prefix / whatever.jpg ).

What is the deal here?

At the same time, I solved the problem with a small hack to change directories ...

 (r'^admin-media/(?P<path>.*)$', 'django.views.static.serve', ... ), ADMIN_MEDIA_PREFIX = '/admin-media/../admin-media/' 

... but I would prefer to configure this correctly. It seems django is trying to be smart and do something on my behalf, but to delve into the process. Any ideas?

EDIT - I manually maintain the administration tools because I use grappelli, which provides admin template / media replacement.

+4
source share
3 answers

If you are using Grappelli, you can set the media administrator when using runserver by specifying the command line argument --adminmedia . Here is an example:

 python manage.py runserver --adminmedia=/path/to/grappelli/media 

Where /path/to/grappelli/media is the full path to your media installation directory in Grappelli.

+1
source

You do not need to specifically maintain administrative tools when using the development server - this should happen automatically.

0
source
  • I think it’s easier to just reference the django media resource in your local system, the same directory that you use in the production process, than to expose a lot if the PRODUCTION is in the settings.

    / li>
  • As Daniel rightly pointed out, django uses administrative media by default. No additional configuration is required. So the problem may be something else. Try chmod 777 in the templates directory, it can fix the problems.

0
source

All Articles