Django Apache/mod_python Admin CSS not appearing with admin tables

Ana picture Ana · Jan 26, 2009 · Viewed 9.3k times · Source

I have Windows XP/Django/apache/mod_python working on localhost. All parts are working with the exception of the admin CSS not rendering. The admin works, but no html formatting. I've made additions in:

settings.py

  INSTALLED_APPS
  'django.contrib.admin',

urls.py

  from django.contrib import admin
  admin.autodiscover()
  (r'^admin/(.*)', admin.site.root),

conf/http.conf

  <Location "/"> 
    SetHandler python-program
    PythonPath "['C:/django'] + sys.path"
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonDebug On
  </Location>

  <Location "/cpssite/"> 
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE myapplication.settings
    PythonInterpreter /myapplication
    PythonDebug On
  </Location>

I'm stumped. Is there more code I should have added somewhere?

Answer

Harper Shelby picture Harper Shelby · Jan 26, 2009

Does your ADMIN_MEDIA_PREFIX exist? Is it different from MEDIA_URL? Did you include the trailing slash? Is Apache handled to correctly serve up the admin media?

The default Django configuration has the admin media located at {Django install dir}/contrib/admin/media. ADMIN_MEDIA_PREFIX defaults to /media/. So you need to add something like this to your Apache config:

Alias /media/ /path/to/django/contrib/admin/media/

This will tell Apache that requests for mysite.com/media/css/whatever.css mean to serve up /path/to/django/contrib/admin/media/css/whatever.css, which should solve your issue.