[mod_python] Where do you put your py modules... ? [alias paranoid protector]

Sean Davis sdavis2 at mail.nih.gov
Mon Oct 9 08:44:48 EDT 2006


On Monday 09 October 2006 08:23, durumdara wrote:
> Sean Davis írta:
> > Why not make a "Page" class that contains all the functionality that you
> > want for each page, and then inherit from it to supply the body? 
> > Alternatively, use a template system (as you suggest).
>
> Dear Sean !
>
> This is very-very good idea !
> I have only one question:
> I must set the python handler script in the apache config. This is a
> file (one file).
> So Apache call this file to handle all of the requests.
> Because that I need to call a page class that user requested
> (req.filename), if I want to show result presented with this (inherited)
> page class.
>
> Apache - > Handler -> myscript::handler -> req.filename ->
> call(req.filename) -> return

req.filename has a class in it that inherits from your page class.  That page 
class is defined in some file, perhaps your handler file, and is inherited by 
some class in the file req.filename.  But you can do it however you like.  

I would suggest not worrying so much about the "right" way to do it quite yet.  
Get a framework that works for you and then refactor as it becomes obvious 
what needs to be done differently.  That is the cool thing about python and 
mod_python--there are many ways to do it.

> Or is exists another way to set Apache: if the requested file have .py
> extension, Apache start it without your call (with predefined user
> function) ?
>
> Apache -> ?.py? req.filename -> call(req.filename) -> return
>
> Thanks for your help, and thanks for help I got from everybody:
> dd


Might I make a suggestion that if you are trying to design an interactive 
website that you look at the various frameworks that are available FIRST, 
decide what makes sense in them, and then go on to write your own stuff.  
Look at Ruby-on-rails, Catalyst, CGI::Application, CherryPy, Django, 
TurboGears, etc.  See how they handle the problems that you are facing.  
Then, sit down with pencil and paper and decide what functionality that you 
need and where.  I personally like the ruby-on-rails/catalyst systems that do 
their own URL management, etc. and do not exist in the filesystem, but you 
are free to do what you want, of course.  



More information about the Mod_python mailing list