google-code-export / django-grappelli

Automatically exported from code.google.com/p/django-grappelli
0 stars 0 forks source link

How to get the grappelli media files to work with the debug server? #149

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
For some reason, I am completely unable to get Grappelli working with the
debug server.

Here are my settings:

MEDIA_ROOT = '/Users/Nick/Code/pmw/media'
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/media/admin/'

The Grappelli media files are located at
'/Users/Nick/Code/pmw/media/grappelli'.

With these settings, I'm able to successfully resolve the following:

http://localhost:8000/media/grappelli/js/admin/CollapsibleGroup.js

However, when I change ADMIN_MEDIA_PREFIX to:

ADMIN_MEDIA_PREFIX = '/media/grappelli/'

The file is no longer being served:

"Page not found: /media/grappelli/js/admin/CollapsibleGroup.js"

I'm using this code to serve static files on debug server:

if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT.replace('\\','/')}),
    )

Pulling my hair out. Would love any help.

Thanks.

Original issue reported on code.google.com by intellin...@gmail.com on 21 Dec 2009 at 9:11

GoogleCodeExporter commented 9 years ago
a bit strange. from what I see here this should work.

however, did you try using --adminmedia ... 
python manage.py runserver localhost:8000
--adminmedia=/Users/Nick/Code/pmw/media/grappelli/

another thing you could try is to explicitely define your admin-media directory 
as
static.server like this:
(r'^media/grappelli/(?P<path>.*)$', 'django.views.static.serve', 
{'document_root':
'/Users/Nick/Code/pmw/media/grappelli/'}),

hope this helps.
regards,
patrick

Original comment by sehmaschine on 22 Dec 2009 at 10:11

GoogleCodeExporter commented 9 years ago
Ah - good tips - I knew there had to be some server-level switch the debug 
server is
making for admin media, as it always defaults to the django install's 
admin-media.

I'll give those a try.

Thanks!

Original comment by intellin...@gmail.com on 22 Dec 2009 at 1:30

GoogleCodeExporter commented 9 years ago
By the way, I did try the second thing - explicitly defining the admin-media 
dir with
the static server with no luck.

Original comment by intellin...@gmail.com on 22 Dec 2009 at 1:31

GoogleCodeExporter commented 9 years ago
For me, using adminmedia option is kind of workaround - it works but there 
should 
be a better solution.

It would be much simpler to put additional media at, for example, 'grappelli' 
directory 
within static document_root. Templates are already overridden so implementation 
would be quite easy ( src={{ MEDIA_URL}}grappelli/... ), as far as I can 
imagine as I 
don't really know the impact on the admin internals.

And usage of 'adminmedia' optition should probably be pointed out at install 
documentation (I haven't been even aware of it's existence ;-)).

Oh, and patrick, second approach you have suggested doesn't really work, at 
least for 
me - I'm using Django 1.1. I'm trying to get it working this way for much too 
long 
and it is very frustrating...

Have this at my settings module:
ADMIN_MEDIA_PREFIX = '/admin-media/'

And this at urls.py:

if settings.DEBUG:
    urlpatterns += patterns('django.views',
        # admin-media
        (r'^%s(?P<path>.*)$' % settings.ADMIN_MEDIA_PREFIX[1:] , 'static.serve',
        {
            'document_root': os.path.join(settings.PROJECT_ROOT, 'admin-media'),
            'show_indexes' : True,
        }),
        ...

and its before I bind admin app.

It seems that changes at urls.py didn't go into life as I got strange error if 
I try to list 
the directory: "Permission denied: /admin-media/"...

I tried to directly run django.views.static.directory_index on my 
django/contrib/admin/media directory and it returned as expected (means without 
any error). So I'm totally lost here.

Original comment by LukaszBa...@gmail.com on 22 Dec 2009 at 1:35

GoogleCodeExporter commented 9 years ago
I had this problem for a while and finally got a good understanding of what's 
going on.

You need to use the --adminmedia flag because otherwise django will default the 
admin
folder to django/contrib/admin/media in your pythonpath. *And it will also set 
up the
static serve urlconf entries automatically.  This is the real problem.  You 
can't
just override the urlconf settings because the admin will still have the file 
system
path set wrong.  So you need to set the --adminmedia path as well so the urlconf
looks in the right place.

The only thing I would recommend is to make the setup instructions a little more
clear.  The grappelli media folder _completely replaces_ the default django 
media
folder.  So just change everything to point there and you're in good shape.

Original comment by marco.ro...@gmail.com on 7 Jan 2010 at 3:27

GoogleCodeExporter commented 9 years ago
Ah - awesome. Thank you for the explanation. That pretty much drove me crazy 
for 8+
hours.

Original comment by intellin...@gmail.com on 7 Jan 2010 at 3:54

GoogleCodeExporter commented 9 years ago
usage of --adminmedia is in the docs now ... thanks for the hint.

but: you can put grappelli-media wherever you want to ... you just need to tell 
your
server to use that directory as your (admin)-media-directory. of course, 
that´s not
necessary if you use djangos built-in dev-server. without the dev-server, you 
need to
change your server-setup (e.g., if you use /admin-media/ as your 
ADMIN_MEDIA_PREFIX,
you need to tell your server how /admin-media/ is served).

Original comment by sehmaschine on 7 Jan 2010 at 4:19

GoogleCodeExporter commented 9 years ago
See this answer from stackoverflow: 
http://stackoverflow.com/questions/1081596/django-serving-admin-
media-files#1656828

It seems that the ADMIN_MEDIA_PREFIX only has effect if the full domain name is 
supplied:
ADMIN_MEDIA_PREFIX = 'http:/localhost:8000/admin-media/'

Original comment by dirk.van...@gmail.com on 7 Apr 2010 at 1:05

GoogleCodeExporter commented 9 years ago
@dirk: we never use the full domain with ADMIN_MEDIA_PREFIX, so that can´t be 
an issue.

Original comment by sehmaschine on 8 Apr 2010 at 10:32

GoogleCodeExporter commented 9 years ago
@dirk: thanks! that helped!

Original comment by martin.b...@gmail.com on 2 Sep 2010 at 9:50