ANN: htmlbuilder.py - another HTML generator

Gerard Flanagan grflanagan at yahoo.co.uk
Thu Mar 30 21:23:06 CEST 2006


In the hope that it may be useful, a simple Html Generator:

    http://gflanagan.net/site/python/htmlbuilder/htmlbuilder.py

It requires 'elementtree' :
http://www.effbot.org/zone/element-index.htm

Example:

    html = HtmlBuilder( doctype='strict')
    page = html.page('Test Page')
    page.comment('Begin Header')
    page.template('HEADER')
    page.comment('Begin Content')
    page.template('CONTENT')
    page.comment('Begin Footer')
    page.template('FOOTER')

    header = html.include( '../test/header.html' )
    content = html.div(id='content')
    content.h3('Welcome ').template('USER').literal('!!')
    footer = html.div(id='footer')
    footer.cheetah('Cheetah says the date is $DATE')

    content %= [{ 'USER': 'Arthur Dent' }]
    footer %= [{ 'DATE': '10/3/06' }]
    page %= [{'HEADER': header,'CONTENT': content,'FOOTER': footer }]
    print
    print page

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 1st September 2004), see www.w3.org">
<title>Test Page</title>
</head>
<body>
<!-- Begin Header -->
<div id="header">
<h1>The Website At The End of The Universe</h1>
</div>
<!-- Begin Content -->
<div id="content">
<h3>Welcome Arthur Dent!!</h3>
</div>
<!-- Begin Footer -->
<div id="footer">Cheetah says the date is 10/3/06</div>
</body>
</html>

Gerard




More information about the Python-list mailing list