Python Webpages

Jon Ribbens jon+usenet at unequivocal.co.uk
Tue Apr 30 11:46:54 EDT 2002


In article <3CCEAE2B.8000300 at gmx.net>, Tom Chance wrote:
><TMPL_VAR NAME=TITLE>
> 
> $template->param(TITLE => 'Hello there!');
> 
> Perhaps Python merely needs an equivalent of this?

Python already has several equivalents of this. I think you can do
better though, which is what jonpy does. You instead do simply:

  $$title$$

and then in your Python code:

  class main(wt.TemplateCode):
    def title(self):
      return "Hello there!"

This more object-oriented approach is both simpler and more powerful,
since you can use class inheritance to very easily make re-usable
configurable objects. Have repeated sections such as table rows is
also very easy using 'sections':

  <!--wt:newsitem-->
    <tr><td><a href="newsitem.html?id=$$%ID$$">$$title$$</a></td></tr>
  <!--wt:/newsitem-->

  class main(wt.TemplateCode):
    class newsitem(rowaccess.RowAccess):
      def main(self, template):
        dbc = website.dbh.cursor()
        dbc.execute("SELECT ID,title FROM newsitems")
        for self.row in dbc.fetchall()
          self.process(template)

Cheers


Jon



More information about the Python-list mailing list