我在让我的 Mod Python 正常工作时遇到问题。
我已经按照mod_python手册找到了here
这是我的 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
注意:我将 www 添加到索引的原因是因为那是 mod_python 教程所说的:
Attempt to import a module by name myscript. (Note that if myscript was in a subdirectory of the directory where PythonHandler was specified, then the import would not work because said subdirectory would not be in the sys.path. One way around this is to use package notation, e.g. "PythonHandler subdir.myscript".)
如果我使用 mod_python.publisher 作为我的 PythonHandler,一切正常。不确定我在这里遗漏了什么。
请您参考如下方法:
我想通了。我的目录与我的 DocumentRoot 不匹配。
感谢有关 mod_wsgi 的回复。我最终会转向 wsgi,但我仍在学习如何使用 Python 进行 Web 开发,我基本上默认学习使用 mod_python。
