简体   繁体   English

mod_python Apache配置

[英]mod_python Apache configuration

I am having issues with getting my Mod Python to work properly. 我在让Mod Python正常工作时遇到问题。

I have followed mod_python manual found here 我遵循了在这里找到的mod_python手册

So here is my Apache setup (I am using Virtual Hosts): 这是我的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>

Here is my handler index.py: 这是我的处理程序index.py:

from mod_python import apache

def handler(req):
    req.content_type = "text\plain"
    req.write("Hello World!")
    return apache.OK

After setting all that up I get the following error: 设置所有这些之后,我得到以下错误:

ImportError: No module named www.index

NOTE: The reason I am adding www to index, is because that is what the mod_python tutorial stated: 注意:我将www添加到索引的原因是因为那是mod_python教程所说的:

Attempt to import a module by name myscript. 尝试通过名称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, eg "PythonHandler subdir.myscript".) (请注意,如果myscript在指定PythonHandler的目录的子目录中,则导入将无法进行,因为该子目录不在sys.path中。解决此问题的一种方法是使用包表示法,例如“ PythonHandler子目录。的MyScript”。)

If I use mod_python.publisher as my PythonHandler, everything works fine. 如果我将mod_python.publisher用作PythonHandler,则一切正常。 Not sure what I am missing here. 不知道我在这里想念的是什么。

I figured it out. 我想到了。 My Directory did not match my DocumentRoot. 我的目录与我的DocumentRoot不匹配。

I appreciate the replies regarding mod_wsgi. 我感谢有关mod_wsgi的回复。 I will eventually move to wsgi but I am still learning how to use Python for web development and I basically defaulted to learn using mod_python. 我最终将转到wsgi,但是我仍在学习如何使用Python进行Web开发,并且我基本上默认使用mod_python学习。

If you can stop using mod_python as it is abandoned now. 如果您可以停止使用mod_python,因为它已被废弃。 mod_wsgi is the way to go. mod_wsgi是必经之路。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM