Home Login Create account Contact Help
Close

Login to your account

Other Options

Comments feed

In response to XML or Text for Python Templates?

There are a number of (very good) templating systems and languages available for Python. They fall in to one of two camps; either they are XML based, like Genshi, or they are text based, like Mako. Most programmers favour one or the other, but there is far from a consensus over which is better.

I'd like to use this debate to gather reasons for using one over the other in the context of web development. I suspect there will be no clear winner, but it should serve as a useful resource for those faced with the decision!

...

NB. You can post code with the [code] bbcode tag. Many languages are supported. e.g.

[code python]

print "Hello, World!"

[/code] 



Simon Willison argues for "Text"
Mon, 15 Oct 2007 by simonw
Rank 2. Average +0.5 ( 11 votes )

XML template engines are great if you are generating XML, but in Web applications that isn't always the case. HTML is a better format for real-world Web sites than XHTML (less compatibility issues, better browser support), and most applications need to generate plain text formats such as e-mails as well. While XML template systems can be used for non-XML output doing so tends to be quite uncomfortable and can be overly verbose.

Martijn Faassen comments...
Mon, 15 Oct 2007 by faassen
Another prominent use case for text-based templates besides templating email is templating SQL. This has seen prominent use in Zope 2. This technique is becoming less relevant with the more recent prominence of object relational systems.
Anthony Briggs comments...
Wed, 17 Oct 2007 by anthony
According to Martijn Faassen:

Another prominent use case for text-based templates besides templating email is templating SQL.

I'm not so sure that's such a big deal. I've found that most SQL can be dealt with using Python's normal %s interpolation - using a templating library may be overkill unless you have really massive SQL commands.
Aaron Bentley comments...
Tue, 13 Nov 2007 by abentley
It's certainly true that formats unrelated to XML are not good candidates for xml-based templating. But HTML is not a good example of this. XHTML is easily transformed into HTML, and XML templating systems like Kid, Genshi, and probably others, make it extremely easy to do this as a final output stage.


Return to debate