mod_python Apache配置

问题描述:

我遇到了让我的Mod Python正常工作的问题。mod_python Apache配置

我按照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 

注:我加入万维网索引究其原因,是因为这是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,一切工作正常。不知道我在这里错过了什么。

如果您可以停止使用mod_python,因为它现在被放弃了。 mod_wsgi是要走的路。

+1

你不回答OP的问题 – joaquin 2010-09-30 14:21:07

+4

是的,他很好。 Lark只是遵循mod_python教程,所以将他指向mod_wsgi并为他节省一些头发非常重要。 – 2010-09-30 14:34:21

+0

这个答案不是答案,但它是相关的信息。作为对原文的评论,它可能会更好。 – ddoxey 2015-03-19 17:08:18

我想通了。我的目录与我的DocumentRoot不匹配。

我赞赏有关mod_wsgi的回复。我最终将迁移到wsgi,但我仍然在学习如何使用Python进行Web开发,并且我基本上默认学习使用mod_python。

+0

不好的选择。现在切换,以便您可以专注于Web开发,而不是管理没有太多用处的产品。 – 2010-09-30 15:28:14