Setting up Python on Windows/ Apache?

前端 未结 3 991
夕颜
夕颜 2020-12-29 00:06

I want to get a simple Python \"hello world\" web page script to run on Windows Vista/ Apache but hit different walls. I\'m using WAMP. I\'ve installed mod_python

3条回答
  •  有刺的猬
    2020-12-29 00:32

    You do not NEED mod_python to run Python code on the web, you could use simple CGI programming to run your python code, with the instructions in the following link: http://www.imladris.com/Scripts/PythonForWindows.html

    That should give you some of the configuration options you need to enable Python with CGI, and a google search should give you reams of other info on how to program in it and such.

    Mod_python is useful if you want a slightly more "friendly" interface, or more control over the request itself. You can use it to create request filters and other things for the Apache server, and with the publisher handler you get a simpler way of handling webpage requests via python.

    The publisher handler works by mapping URLs to Python objects/functions. This means you can define a function named 'foo' in your python file, and any request to http://localhost/foo would call that function automatically. More info here: http://www.modpython.org/live/current/doc-html/hand-pub-alg-trav.html

    As for the Apache config to make things work, something like this should serve you well

    
      SetHandler mod_python
      PythonHandler mod_python.publisher
      PythonDebug On
    
    

    If you have /var/www/html/ set up as your web server's root and have a file called index.py in the python/ directory in there, then any request to http://localhost/python/foo should call the foo() function in index.py, or fail with a 404 if it doesn't exist.

提交回复
热议问题