mod_python Apache 配置
我在使用 Mod Python 时遇到了一些问题。
我按照这里的 Mod Python 手册进行了操作:这里
这是我的 Apache 设置(我在使用虚拟主机):
<VirtualHost *:80>
ServerName hostname
DocumentRoot "C:/Documents and Settings/username/hostname/www"
<Directory "C:/Documents and Settings/username/hostname">
DirectoryIndex index.py
AddHandler mod_python .py
PythonHandler www.index
PythonDebug On
</Directory>
</VirtualHost>
这是我的处理程序 index.py:
from mod_python import apache
def handler(req):
req.content_type = "text\plain"
req.write("Hello World!")
return apache.OK
在设置好这些之后,我遇到了以下错误:
ImportError: No module named www.index
注意:我在 index 后面加上 www,是因为 Mod Python 教程里是这么说的:
尝试通过名称导入一个模块 myscript。(注意,如果 myscript 在指定 PythonHandler 的目录的子目录中,那么导入将无法工作,因为该子目录不在 sys.path 中。解决这个问题的一种方法是使用包的表示法,例如 "PythonHandler subdir.myscript"。)
如果我使用 mod_python.publisher 作为我的 PythonHandler,一切都正常。我不太确定我漏掉了什么。
2 个回答
0
如果你能停止使用mod_python,那就最好了,因为它现在已经不再维护了。推荐使用mod_wsgi,它是更好的选择。
1
我搞明白了。我的目录和文档根目录不匹配。
感谢大家关于mod_wsgi的回复。我最终会转向使用wsgi,但我现在还在学习如何用Python进行网页开发,所以我基本上是先从mod_python开始学的。