[mod_python] mod_python Live examples

Bo Lorentsen bl at netgroup.dk
Sat Aug 14 15:39:13 EDT 2004

On Fri, 2004-08-13 at 23:36, Amir Salihefendic wrote:

> I would also really like to see more examples. And get some advice :)!
I do understand your problem, as I was in the same situation for about a
half year ago. I tested the old mod_python (2.7) on apache 1.3, and as I
needed sessions, I felt I had to make to much code to make it worth the

But then I tested version 3.x and apache2, and it all changed, it now
has sessions, and other "basic" stuff, and it all work as expected.
mod_python don't work as php, but I found it more easy to structure my
code, when I got use to the "new" way of modelling.

Hmm, I don't know if this is usefull information :-)

> Anyway, I have also done some work in PHP, ASP and eRuby - - and I must 
> say that mod_python is way more powerful - - especially because you 
> have such a control over the Apache server. The publisher handler is 
> really great - mixing that up with PSP for handling templates - - and 
> boom, you got a really neat and powerful web-development tool! But you 
> really got to know what you are doing - -because there isn't much of 
> help out there...
Well, the python language are very common and you can get all the help
you like, and af for mod_python, this mailling list have some quite nice
and helpfull people, and they know stuff, too :-)

> Anyway, some of you elite mod_python users, couldn't you post some 
> advice - tips and tricks?
> Here is some aspects I want to know more about:
Good idea ... I answer a few :-)

> - How do you build your application (structure)?
I use a OO model of "html renders", and database relations to
automaticlly generate HTML form output. This way I can concentrate my
mind on data relations and data flow (I am not a good web designer, so I
make it easy for somebody else to deside how things must look). I even
have build my own database abstraction layer, that I use both in C++ and
Python (its written in C++). 

It is so nice to have only (I used four before) two languages to write
in : Python for WUI and general scripting, and C/C++ for high
performance backend code.
> - How do you transport data in your application? Of course, you may use 
> publisher, you own handlers etc - - But how do you do internal data 
> transportation (i.e. for your own function calls, callbacks, classes 
> etc.)?
A homebuild HTML render class library, so you will se absolut NO HTML in
my normal Python code, as it is issolated in a few modules.

> - How do you optimize your application?  What can optimize an 
> application (i.e. your experience with optimizing applications)?
Well, have not done much here, python has an OK speed, and my biggest
problem remains the database and not Python. I use connection pools for
the database but that is about it for now.

> - How do you debug?
Now, this is what really makes Python shine ... I use the python
exception system, and this is really nice. I make sure to raise
exceptions whenever something is wrong and then I catch them in the
finale "render" function. 

Here I can print out stacktraces, or even send them to myself as an
email, and make i nice message to the enduser.

I really like the exception model (also in C++), and the only
alternertive to Python would be Ruby, but Ruby uses "memory sweep GC"
(as in Java and D) and I hate that :-)

> - How do you handle access to a database? Do you use global connection? 
As I wrote, I made me own DB abstraction (addes type checking, 
relations and more), but I also uses psycopg for some reporting. I quess
the connection is like a global connection, and as I use the apache2
process model, this works out just nice. 

And yes ... I use PostgreSQL.

> Could you share how you have builded your database system?
That would be a big issue and not very geneal (except if you make a
payment system :-)), what exactly do you what to know ?

> Well, just write about your own experience ;-)
Well I tried :-)


More information about the Mod_python mailing list