[Tutor] Python equiv to PHP "include" ?

Jay Loden python at jayloden.com
Thu Sep 29 23:16:57 CEST 2005


Alan, thanks for your responses, they're quite helpful. I suspect the real 
problem I'm having is simply trying to switch modes of thinking to CGI style 
or mod_python style instead of the PHP style embedded code. 

The whole point of this exercise for me was to decide which language I prefer 
for web development and evaluate Python for web work. So far, I've found PHP 
much easier to work with and less "clunky" in terms of what I'm trying to do 
- but I believe that's very much a function of my thinking being rooted in 
the PHP style. 

If Im understanding this right...the Pythonic/CGI method for something like 
this is to import a template module of some kind, then call methods from that 
template to display the template, with other Python code in the middle that 
takes care of form processing? 

The solution I have now feels smoother, since all I do is put content 
into .htm files, then pull them into a template that's basically an html 
sandwich. This gives me capability to stick a <?php ?> section into the .htm 
file itself - for example a form with some dynamic content/variables - and 
then from a user perspective, all they see is a normal html page.  

From a server side, it's seeing one big PHP script that includes both template 
code and form code, but without me needing to write any templating code into 
the form itself - instead I just call the form into the template.  With 
Python, it seems like this kind of approach is impossible, and it also means 
that my form would probably have to have some kind of special extension, like 
"form.py" (so the handler knows what to do with it) instead of just being 
located at "form.htm" - am I following this all correctly? 

Does anyone know of any soup-to-nuts CGI programming examples online for 
Python that might make this clearer so I can bug the list less and just read 
some example code?

-Jay



More information about the Tutor mailing list