views:

542

answers:

2

HI guys. I was trying to configure my django project in a subdirectory of the root, but didn't get things working.(LOcally it works perfect). I followed the django official django documentarion to deploy a project with mod_python. The real problem is that I am getting "Page not found" errors, whenever I try to go to the admin or any view of my apps.

Here is my python.conf file located in /etc/httpd/conf.d/ in Fedora 7

LoadModule python_module modules/mod_python.so

SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonDebug On
PythonPath "['/var/www/vhosts/mysite.com/httpdocs','/var/www/vhosts/mysite.com/httpdocs/mysite'] + sys.path"

I know /var/www/ is not the best place to put my django project, but I just want to send a demo of my work in progress to my customer, later I will change the location.

For example. If I go to www.domain.com/mysite/ I get the index view I configured in mysite.urls. But I cannot access to my app.urls (www.domain.com/mysite/app/) and any of the admin.urls.(www.domain.com/mysite/admin/)

Here is mysite.urls:

urlpatterns = patterns('',

url(r'^admin/password_reset/$', 'django.contrib.auth.views.password_reset', name='password_reset'),
(r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done'),
(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm'),
(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
(r'^$', 'app.views.index'),
(r'^admin/', include(admin.site.urls)),
(r'^app/', include('mysite.app.urls')),
(r'^photologue/', include('photologue.urls')),

)

I also tried changing admin.site.urls with ''django.contrib.admin.urls' , but it didn't worked. I googled a lot to solve this problem and read how other developers configure their django project, but didn't find too much information to deploy django in a subdirectory. I have the admin enabled in INSTALLED_APPS and the settings.py is ok.

Please if you have any guide or telling me what I am doing wrong it will be much appreciated.

THanks.

A: 

I'm using mod_wsgi, so I'm not sure if it's all the same. But in my urls.py, I have:

(r'^admin/(.*)', admin.site.root),

In my Apache config, I have this:

Alias /admin/media/ /usr/lib/python2.5/site-packages/django/contrib/admin/media

Your path may vary.

Fred Larson
A: 

If your settings.py is correct and has your correct INSTALLED_APPS and it works in the development server, then I'd say it's you Apache configuration file.

Try running my python app to create Apache configuration files for mod_python + Django. The source is here at github.com. Once you have a working configuration file, you can modify it.

Run like this:

C:\Users\hughdbrown\Documents\django\Apache-conf>python http_conf_gen.py --flavor=mod_python --source_dir=. --server_name=foo.com --project_name=foo
Writing 'foo.vhost.python.conf'

Result looks like this:

# apache_template.txt
NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName foo.com

    DocumentRoot "./foo/"

    <Location "/">
        # without this, you'll get 403 permission errors
        # Apache - "Client denied by server configuration" 
        allow from all

        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        PythonOption django.root /foo

        PythonDebug On
        PythonPath "[os.path.normpath(s) for s in (r'.', r'C:\Python26\lib\site-packages\django') ] + sys.path"
        SetEnv DJANGO_SETTINGS_MODULE foo.settings
        PythonAutoReload Off
    </Location>

    <Location "/media" >
        SetHandler None
        allow from all
    </Location>

    <Location "/site-media" >
        SetHandler None
        allow from all
    </Location>

    <LocationMatch "\.(jpg|gif|png)$">
        SetHandler None
        allow from all
    </LocationMatch>
</VirtualHost>
hughdbrown