[Web-SIG] Pure Python HTML?
Bill Janssen
janssen at parc.com
Wed Apr 13 04:45:43 CEST 2005
> 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)
Bill
More information about the Web-SIG
mailing list