简体   繁体   English

apache虚拟主机与django一起使用

[英]apache virtual host to work with django

My project is under: /home/projects/testing and I'm adding this to the buttom of my /etc/httpd/conf/httpd.conf file on Centos machine, but that is not working, 我的项目位于/ 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>

but when requesting http://localhost/testing/jobs for example, I get: 但是例如当请求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

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

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

The path looks okay to me, I've just double checked that items in sys.path work with trailing slashes. 该路径对我来说看起来还可以,我只是仔细检查了sys.path中的项目是否可以使用斜杠。

I'd suggest that this is a file permissions issue: 我建议这是一个文件权限问题:

  • Does the user apache is running under have access to the project files? 用户apache是​​否在运行状态下有权访问项目文件?
  • Is selinux preventing access? selinux是否阻止访问?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM