mod_python apache configuration issues
davidf at sjsoft.com
Tue Oct 19 15:18:36 CEST 2004
> Hello all. I've been trying to get my linux server to run mod_python.
> It's a Mandrake 10 linux box, and apache/mod_python are installed from
> The rpm installed the python module as:
> And added a config file for apache:
> The apache config files contained the following before my modifications:
> <IfDefine HAVE_PYTHON>
> <IfModule !mod_python.c>
> LoadModule python_module extramodules/mod_python.so
> <IfModule mod_python.c>
> Now after reading the docs installed into /usr/share/doc for mod_python
> and going through the directions at python.org, I've also changed the
> config file to add a few lines to one of the directives:
> <Directory /var/www/html>
> Options -Indexes FollowSymLinks MultiViews
> AllowOverride All
> AddHandler mod_python .py
> PythonHandler mptest
> PythonDebug On
> Now when I put the url into a browser:
> I get a popup from the browser because it doesn't know how to handle
> mptest.py, and it asks what you want to do with the file (open it with
> an application, save it to disk, etc). I can choose to open the file
> with a text editor, and all it shows is the text "hello world".
> That's the output of the mptest.py script.... apache isn't feeding the
> browser the code from the mptest.py, only the output. (Otherwise when I
> open it in a text editor I'd see the entire mptest.py script.
> Contents of the mptest.py script:
> from mod_python import apache
> def handler(req):
> req.write("Hello World!")
> return apache.OK
> I'm not a python developer, but have been working with Linux and Apache
> for a number of years. I'm not sure where to go from here. It appears
> that the script gets compiled - there is a mptest.pyc file in the
> directory now. Why is it sending my browser the mptest.py file with the
> stdout of the script?
> Thanks in advance. Any help on this is appreciated.
This is working properly, all you want to do is set the content type so
that your browser can understand it:
req.content_type = "text/plain"
or something like that should do it.
More information about the Python-list