python - Windows 上的 mod_wsgi WSGIPythonPath 多路径

标签 python django windows apache mod-wsgi

Windows 8.1 x64 - Python 3.4.1 (pyzo_distro-2014a.win64) - Apache httpd-2.4.10-win64 - mod_wsgi-3.5.ap24.win-amd64-py3.4

如何设置多个路径?
好像只设置了最后一条路径。

WSGIPythonPath C:/test1;C:/test2;C:/test3

在 Apache 日志文件中(带有 LogLevel 信息):

mod_wsgi (pid=3568): Initializing Python.
mod_wsgi (pid=3568): Attach interpreter ''.
mod_wsgi (pid=3568): Adding '(null)' to path.
mod_wsgi (pid=3568): Adding '(null)' to path.
mod_wsgi (pid=3568): Adding 'C:/test3' to path.
AH00354: Child: Starting 64 worker threads.

同样的结果:

WSGIPythonPath "C:/test1;C:/test2;C:/test3"

这行不通:

WSGIPythonPath "C:/test1";"C:/test2";"C:/test3"

因为 WSGIPythonPath 只接受一个参数。

谢谢。

最佳答案

作为使用 WSGIPythonPath 指令添加目录的替代方法,您可以从代码中将目录添加到路径:

import sys, os
paths = ['C:\test1', 'C:\test2', 'C:\test3']
for path in paths:
    if path not in sys.path:
        sys.path.append(path)

或者,如果你需要添加当前目录(对于 Flask/Webapp2 并不少见),你可以放置

您可以将以下内容放在 main.py 中其他导入的上方:

import sys, os
path = os.path.dirname(os.path.abspath(__file__))
if path not in sys.path:
    sys.path.append(path)

假设您的 Apache 服务器配置如下所示:

WSGIScriptAlias /scripts "C:/web/wsgi_scripts/main.py"
WSGICallableObject app

<Directory "C:/web/wsgi_scripts">
<Files main.py>
Require all granted
</Files>
</Directory>

关于python - Windows 上的 mod_wsgi WSGIPythonPath 多路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26163113/

相关文章:

javascript - 如何检查 django 模板中哪些复选框已选中或未选中?

c++ - 我可以得到单独的 DLL 来分别解析它们导入的 DLL 吗?

windows - FFmpeg 编译与编码器 x264 未找到 Windows

python - "detail": "Method\"GET\"not allowed." Django Rest Framework

python - 使用Python的频谱分析仪?

python - 如何在 Python 中对集合运行操作并收集结果?

python - 是否有任何 XOR 位减少操作数或函数?

django - 需要帮助设置 django-filetransfers

windows - AutoIT & VBS - 从 Windows 锁定屏幕将 PC 添加到域

Python:合并两个字典