views:

33

answers:

2

When I was using the built-in simple server, everything is OK, the admin interface is beautiful:

python manage.py runserver

However, when I try to serve my application using a wsgi server with django.core.handlers.wsgi.WSGIHandler, Django seems to forget where the admin media files is, and the admin page is not styled at all:

gunicorn_django

How did this happen?

+1  A: 

Django by default doesn't serve the media files since it usually is better to serve these static files on another server (for performance etc.). So, when deploying your application you have to make sure you setup another server (or virtual server) which serves the media (including the admin media). You can find the admin media in django/contrib/admin/media. You should setup your MEDIA_URL and ADMIN_MEDIA_URL so that they point to the media files. See also http://docs.djangoproject.com/en/1.2/howto/static-files/#howto-static-files.

muksie
A: 

When I look into the source code of Django, I find out the reason.

Somewhere in the django.core.management.commands.runserver module, a WSGIHandler object is wrapped inside an AdminMediaHandler.

According to the document, AdminMediaHandler is a

WSGI middleware that intercepts calls to the admin media directory, as defined by the ADMIN_MEDIA_PREFIX setting, and serves those images. Use this ONLY LOCALLY, for development! This hasn't been tested for security and is not super efficient.

And that's why the admin media files can only be found automatically when I was using the test server.

Now I just go ahead and set up the admin media url mapping manually :)

Satoru.Logic