简体   繁体   中英

mod_python Apache configuration

I am having issues with getting my Mod Python to work properly.

I have followed mod_python manual found here

So here is my Apache setup (I am using Virtual Hosts):

<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:

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:

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, eg "PythonHandler subdir.myscript".)

If I use mod_python.publisher as my PythonHandler, everything works fine. Not sure what I am missing here.

I figured it out. My Directory did not match my DocumentRoot.

I appreciate the replies regarding 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.

If you can stop using mod_python as it is abandoned now. mod_wsgi is the way to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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