Web programming ...

has has.temp2 at virgin.net
Fri May 7 13:05:01 EDT 2004


remi at cherrypy.org (Remi Delon) wrote in message news:<585c0de9.0405070102.47a481a5 at posting.google.com>...

> I see 3 common ways of dynamically generating HTML (or any other type
> of text). Let's say we have a variable called "name" that contains
> "world". The 3 common ways are:
>         (1) Embedding HTML in python: return "<html><body>Hello,
> %s</body></html" % name
>         (2) Embedding python in HTML (templating language):
> <html><body>Hello, $name$</body></html> (or some other notation
> depending on the templating language). I would also put things like
> XSLT in that category.
>         (3) The "programmatic" approach: return HTML(BODY("Hello, %s"
> % world)) (or some other notation)

There's a fourth option: compile your HTML template into a Python
object model that can be manipulated programmatically. IMO this is by
far the best approach for template-based rendering: it's extremely
simple yet powerful, highly portable (not being bound to any
particular web framework) and completely separates presentation logic
from markup (other approaches typically separate only model logic).

See PyMeld, Nevow.Renderer and my own HTMLTemplate
<http://freespace.virgin.net/hamish.sanderson/htmltemplate.html> (you
can find various scripts using HTMLTemplate around my site).

HTH



More information about the Python-list mailing list