[Web-SIG] Pure Python HTML?
Robert Brewer
fumanchu at amor.org
Wed Apr 13 07:12:14 CEST 2005
Bill Janssen wrote:
> > I don't know about you, but generating HTML with pure
> Python code can be
> > messy--ONE reason why we introduce templateing languages in
> the first
> > place. Often (not always) the best way to end up with XHTML
> is to start
> > with a valid or almost-valid XML document and then infuse
> the dynamic
> > content.
>
> Indeed. And in Python I do it with string formatting:
>
> template = """
> <HTML>
> <HEAD>
> <TITLE>%(title)s</TITLE>
> </HEAD>
> <BODY>
> <H1>%(title)s</TITLE>
> <P>Author: %(author)s
> <P>something interesting here
> </BODY>
> """
>
> dynamic_content = {}
> # fill in dynamic content here, or perhaps it's a dict read from a DB
> dynamic_content['title'] = 'How to write a Web service'
> dynamic_content['author'] = 'Someone Good'
>
> request.reply(template % dynamic_content)
Indeed, indeed, Bill. You might appreciate my Assembly class from
Cation:
http://www.aminus.org/rbre/cation/html/assembly.py
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Web-SIG
mailing list