apache 虚拟主机与 django 一起使用

发布于 2024-08-27 02:15:52 字数 1177 浏览 4 评论 0 原文

我的项目位于:/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

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,

<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:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执妄 2024-09-03 02:15:52

您需要在 PythonPath 中同时包含项目文件夹和测试文件夹,因为您的项目使用的路径中不含“testing”:

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

You want both, the projects folder and the testing folder in your PythonPath, because your project uses paths without the "testing" in it:

PythonPath "['/home/projects/', '/home/projects/testing/'] + sys.path"
可爱咩 2024-09-03 02:15:52

该路径对我来说看起来不错,我刚刚仔细检查了 sys.path 中的项目是否可以使用尾部斜杠。

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

  • 运行的用户 apache 是否有权访问项目文件?
  • selinux 是否阻止访问?

The path looks okay to me, I've just double checked that items in sys.path work with trailing slashes.

I'd suggest that this is a file permissions issue:

  • Does the user apache is running under have access to the project files?
  • Is selinux preventing access?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文