Alan Kennedy
modpython at xhaus.com
Sun Feb 17 07:36:32 EST 2002
Daniel, > I managed to run mptest.py ("Hello World" of official > doc) with Apache win32 but I don't manage to run the > others python scripts : > When I run the other python scripts, my browser show > me "hello world"...the same result than mptest.py !! The answer to this question depends on your configuration. If your configuration looks something like this <Directory "/some/directory/"> AddHandler python-program .py PythonHandler mptest </Directory> Then what you're telling Apache is "Run mptest.py whenever anyone requests a URI in the directory "/some/directory" which has the extension ".py". So *all* of the following URIs result in the same call to the "handler" function of "mptest.py". http://someserver.com/some/directory/mptest.py http://someserver.com/some/directory/anotherscript.py http://someserver.com/some/directory/theScriptNameDoesNotMat ter.py The important section of the manual to understand is section 3.2: So what Exactly does Mod-python do? http://www.modpython.org/live/mod_python-2.7.6/doc-html/tut- what-it-do.html In particular, you must understand the section at the bottom called "Some food for thought". > I think I must add or modify other apache python's directives. So > - I woud like to get a good httpd.conf for Apache win32 and Python > module which works. "Works" is a relative thing. "Works" for what purpose is more the right question to ask. I've found that the bare minimum changes to a httpd.conf for mod_python are two changes, 1. to load the modpython module, and 2. to set up a handler module/function. These are handled as follows 1. Start with a clean httpd.conf from the Apache installation, and add the following entries. LoadModule python_module modules/mod_python.{dll|so} There should be a list of "LoadModule"s in the default httpd.conf, just put it with them. Probably best to put it before any other "LoadModule". Then add a python handler for whichever directories you wish. The following directive indicates that myPythonHandler.py should be run whenever any URI ending in ".py" is requested anywhere in the document tree. <Directory /my/document/root/> AddHandler python-program .py PythonHandler myPythonHandler </Directory> So whenever a request arrives for any URI ending in ".py", anywhere in the document hierarchy, at any level, then the "handler" function in the module "myPythonHandler.py" will be run. > - some information about the "standard" headers of python scripts > running in Apache web server. I'm not sure what you mean by "headers". This is not CGI, so you don't need shebang lines, or anything like that. The only headers you need to know about are the HTTP headers sent back with each http response, such as "Content- type", "Content-length", "Content-encoding", and so on. These are set in your handler function as follows def handler(req): req.content_type = "text/html" req.headers_out['Content-Length'] = str(length) Hopefully this well help you get configured and running. Bon chance, Alan. --------------------------------------------- This message was sent using WebMail by CyberGate. http://www.gate.net/webmail
|