views:

48

answers:

3

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.

A: 

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.

Jeremy Kemball
'django.contrib.admin' in INSTALLED_APPS is uncommented. You say 'admin middleware' but a I can't find any admin middlewares - only admin app.
Łukasz Śliwa
Then my hand is officially all played out. Nice answer by laurent, though.
Jeremy Kemball
+1  A: 

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.

laurent-rpnet
Great! Thanks a lot :)
Łukasz Śliwa
That works, but the right way is to use the `django.root` to strip your url, leaving only the part where django will start so you can move your site and only need to change the `django.root`. It's explained here: http://docs.djangoproject.com/en/dev/howto/deployment/modpython/?from=olddocs
laurent-rpnet
Sorry my answer is sliced but I had to stop.. To complement, in your case <Location> is `/` so if you strip it, it stays empty and the doc says you have to leave at least a `/` in the begining so I removed the line, maybe there is a better way... but this one seems to work!
laurent-rpnet
You do not need either django.root or even the enclosing Location block for '/'. Stuff at top level with VirtualHost applies to URL of / anyway.
Graham Dumpleton
+1  A: 

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

Frank Wiles