_RE: Mod_python

Paul Boddie paul at boddie.org.uk
Wed May 4 04:56:41 EDT 2005


Gensek wrote:
>
> I want to use mod_python, but I'm having trouble. Here's what I have in
> my config:
>
> LoadModule python_module /usr/local/apache2/modules/mod_python.so
>
> <Directory /usr/local/apache2/htdocs/python>
>     AddHandler mod_python .py
>     PythonHandler mptest
>     PythonDebug On
> </Directory>

My guess is that you need to add an Alias directive:

Alias /python /usr/local/apache2/htdocs/python

Otherwise, when you try the following URL...

> http://localhost/python/mptest.py

...Apache/mod_python doesn't know where to find the modules/files in
the filesystem corresponding to the "Web path" /python. Apologies if
you've already done this but didn't mention it.

[...]

> Is there any worthwhile alternative to modpython? I find it rather
> troublesome.

There are certainly a number of different options, and it depends on
how much you want to use the mod_python style of programming as to
which of those options you want to evaluate.

If you like Web programming frameworks using the "publisher style" -
that is, where you write Python functions and classes which correspond
to names in the URL, as in the example here...

http://www.modpython.org/live/current/doc-html/tut-pub.html

...then you might want to consider CherryPy, Quixote and Twisted Web
(amongst others).

If you don't care about (or don't care for) Web programming frameworks
using that style, but like a more "servlet style" approach or
mod_python's "handler style", as in the example here...

http://www.modpython.org/live/current/doc-html/inst-testing.html

...then there's jonpy, Snakelets and Webware (amongst others).

I'm a bit biased when it comes to recommending frameworks, since I
always have to mention WebStack which favours a handler/servlet style
rather than the publisher style, although you can obviously build
publishers on top of it, and there are some helper classes included
for such purposes. However, you'll also want to consider how your
application produces its Web pages and whether you'll want to access
databases really easily or not - some frameworks attempt to cover
those issues as well.

WebStack applications can run on Apache (if you can stomach the
configuration, which isn't that hard once you've done it a few times)
but also on other servers and frameworks (if you'd prefer something a
bit more obvious). It has been said that people don't really need this
flexibility, but even if you aren't deploying on Zope (or whatever)
today, it's surely nice to know that you have the chance at some later
point in time without rewriting lots of code.

Paul

P.S. Start here: http://www.python.org/moin/WebProgramming



More information about the Python-list mailing list