views:

4108

answers:

6

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?

+9  A: 

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.

Harper Shelby
It should be noted this must be in the Apache config, .htaccess will not work.
Mark Stahler
For the love of god, why isn't this the accepted answer? Anyway, thanks, had exactly this problem.
Liedman
A: 

Hello,

No. I didn't do anything with this line:

ADMIN_MEDIA_PREFIX = ''

What code should I place?

Thanks,

May

ADMIN_MEDIA_PREFIX = '/media/'
Jeff Bauer
@Jeff Bauer: isn't that the default if nothing is there? That's my understanding (from the online docs).
Harper Shelby
+5  A: 

I used to have the same problem and the following entry in the http.conf worked fine with me:

<Directory "Path-to-python/Lib/site-packages/django/contrib/admin/media/"> 
    AllowOverride None 
    Options None 
    Order allow,deny 
    Allow from all 
</Directory> 

Alias /media/ "Path-to-Python/Lib/site-packages/django/contrib/admin/media/"

<Location "/mysite/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonOption django.root /mysite
    PythonInterpreter mysite
    PythonDebug On
    PythonPath "['C:/Python/Django/apps'] + sys.path"
</Location>
Helmut
Thank you, thank you! I couldn't remember to set the directory and alias sections.
Phil Bennett
+1  A: 

Here is my django-specific apache configuration. Note, django handles every incoming url to the site (location /) except media, where it's disabled, and the data is served from django's media directory.

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

Alias /media  e:/dj/django-trunk/django/contrib/admin/media/
<Location "/media">
  SetHandler None
</Location>
fastmultiplication
+2  A: 

I am having a similar problem but with the project/app running on FreeBSD6.3. The entire application is running on on FreeBSD just fine, but the admin app. doesn't format, i.e. doesn't load its CSS. I tried symbolic linking the admin media directory to my project directory but that doesn't make a difference. It looks like the admin app. is looking elsewhere for its CSS. So I tried a test. In the view which is responsible for displaying the index I added this code:

def index(request): cur_dir = os.getcwd() # added code list_dir = os.listdir(cur_dir) # added code

template = language + '/' + 'index/index.html'
return render_to_response(template, {'dir': cur_dir, 'dircon': list_dir})

to display the current directory and its contents. I expect to see the project directory and its contents.

On my Mac, running the django development server, it does just that. On my FreeBSD system this same code displays the 'root' directory of the operating system.......

The funny thing is that the application is running just fine on the FreeBSD system.

This is the apache conf file:

Listen 192.168.1.62:80

ServerAdmin [email protected] ServerName www.example.com ServerAlias example.com

DocumentRoot /home/django/sites_django/wmssite

<Directory "/home/django/sites_django/wmssite">
 Options -Indexes FollowSymLinks
 AllowOverride None
 Order allow,deny
 Allow from all
</Directory>

<Location "/">
 SetHandler python-program
 PythonHandler django.core.handlers.modpython
 SetEnv DJANGO_SETTINGS_MODULE wmssite.settings

PythonOption django.root /

 PythonDebug On
 PythonPath "['/home/django/sites_django/'] + sys.path"
</Location>

<Location "/site_media">
 SetHandler None
</Location>

this is my settings.py:

MEDIA_ROOT = '' MEDIA_URL = '' ADMIN_MEDIA_PREFIX = '/media/' MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', # added to serve flatpages )

ROOT_URLCONF = 'wmssite.urls'

TEMPLATE_DIRS = ( '/home/django/sites_django/wmssite/templates', )

INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.flatpages', # added to serve flatpages 'django.contrib.admin', 'wmssite.wms', )

and this my urls.py:

from django.conf.urls.defaults import *

Uncomment the next two lines to enable the admin:

from django.contrib import admin admin.autodiscover()

urlpatterns = patterns('wmssite.wms.views', (r'^$', 'index'),

# Uncomment the next line to enable the admin:
(r'^admin/(.*)', admin.site.root),

)

I hope anyone can help me out with this.

Henri
+1  A: 

If you don't want to have admin media use the /media directory, you can specify ADMIN_MEDIA_PREFIX = 'admin_media', then create a link/alias from your webserver which redirects calls to /admin_media/ to the /usr/share/pyshared/django/contrib/admin/media (depending on your OS) for your production server...

duncan