apache虚拟主机与django一起工作

时间:2010-03-30 12:32:39

标签: django apache virtualhost

我的项目位于:/ home / projects / testing,我将它添加到Centos机器上的/etc/httpd/conf/httpd.conf文件的底部,但是这不起作用,

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

但是在请求http://localhost/testing/jobs时,我得到:

Mod_python error: "PythonHandler django.core.handlers.modpython"

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
    result = object(req)

.............

 File "/usr/lib/python2.4/site-packages/Django-1.1.1-py2.4.egg/django/conf/__init__.py", line 75, in __init__
    raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)

ImportError: Could not import settings 'testing.settings' (Is it on sys.path? Does it have syntax errors?): No module named testing.settings

2 个答案:

答案 0 :(得分:3)

你想要PythonPath中的项目文件夹和测试文件夹,因为你的项目使用了没有“测试”的路径:

PythonPath "['/home/projects/', '/home/projects/testing/'] + sys.path"

答案 1 :(得分:0)

路径看起来没问题,我只是仔细检查sys.path中的项目是否使用尾部斜杠。

我建议这是文件权限问题:

  • 用户apache是​​否可以访问项目文件?
  • selinux阻止访问吗?