user257542
user257542

Reputation:

Django + mod_python + apache: admin panel and urls don't work

Whole this day I was trying to configure django on production server. I use mod_python. When I open http: //beta.example.com I see my site but http: //beta.example.com/admin and http: //beta.example.com/441/abc/ doesn't work:

Page not found (404)
Request Method:     GET
Request URL:    http://beta.example.com/admin

{'path': u'admin'}

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.


Page not found (404)
Request Method:     GET
Request URL:    http://beta.example.com/441/abc/

{'path': u'441/abc/'}

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

My urls:

from settings import MEDIA_ROOT
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # static files
    url(r'^static/javascripts/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': MEDIA_ROOT + '/javascripts'}, name='javascripts'),
    url(r'^static/images/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': MEDIA_ROOT + '/images'}, name='images'),
    url(r'^static/stylesheets/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': MEDIA_ROOT + '/stylesheets'}, name='stylesheets'),
    url(r'^static/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': MEDIA_ROOT}, name='static'),
    (r'^admin/', include(admin.site.urls)),
    url(r'^/?$', 'content.views.index', name='root-url'),
    url(r'^(?P<id>[0-9]{2,5})/(?P<slug>[a-z\-]+)/?$', 'content.views.show', name='show-url'),

)

Apache:

DocumentRoot "/var/www/django/beta.example.com/site"

<Location "/">
  allow from all
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE site.settings
  PythonOption django.root /
  PythonDebug On
  PythonPath "['/var/www/django/beta.example.com', '/var/www/django/beta.example.com/site'] + sys.path"
</Location>

<Location "/static" >
  SetHandler none
</Location>

I have no idea what's wrong.

Upvotes: 1

Views: 1061

Answers (3)

Frank Wiles
Frank Wiles

Reputation: 1608

You really don't want to be using mod_python for deployment. I highly suggest moving to mod_wsgi for Django depoyment.

Upvotes: 2

laurent
laurent

Reputation: 908

Not sure if that will solve your problem but in my site.conf for django I had to comment the line:

PythonOption django.root /

to make it work.

Upvotes: 2

Jeremy Kemball
Jeremy Kemball

Reputation: 1275

I'm just throwing this out there, but you have to enable the django admin middleware in your settings file. It's there but commented out right out of the box. If you've done that I don't have any idea what your problem is.

Upvotes: 0

Related Questions