TAGS :Viewed: 4 - Published at: a few seconds ago

[ Apache+django pythonpath confusion: ImportError: Could not import settings 'mysite.settings' ]

I use python 2.4 and django 1.2.2 and apache 2.2.3
Write httpd.conf section like this:

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

settings.py path: /home/usr/www/mysite/
but it doesn't work, when i visit http://localhost/mysite/

ImportError: Could not import settings 'mysite.settings'

i modified it, change /home/usr/www to /var/www and copy settings.py in /var/www it works. So why apache treat two directories differently?

Answer 1


Are you using SELinux? Compare the output of

ls -laZ /var/www

and

ls -laZ /home/usr/www

Chances are that your home directory cannot be accessed by the apache process. If this is the problem, it might be solved as simply as

chcon -R --reference=/var/www /home/usr/www
chmod og+x /home/usr /home/usr/www

BTW: http://docs.djangoproject.com/en/dev/howto/deployment/modpython/ warns that "Support for mod_python will be deprecated in a future release of Django. If you are configuring a new deployment, you are strongly encouraged to consider using mod_wsgi or any of the other supported backends."

Answer 2


Add PythonPath "['/home/usr/www/mysite'] + sys.path"