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] 



Richard Jones argues for "Text"
Mon, 15 Oct 2007 by richard
Rank 4. Average +0.2 ( 8 votes )
XML-only templating engines only restrict choice and thus cause web developers unnecessary pain.

Because of the obsession with XML too many web developers produce XHTML when it's incredibly poorly-supported (IE in particular treats XHTML as tag soup at best, and at worst doesn't render it at all), whereas the non-XML HTML is very well-supported. XML-only templating engines only restrict choice and thus cause web developers unnecessary pain.

Martijn Faassen comments...
Mon, 15 Oct 2007 by faassen
While pure XHTML may be poorly supported by browsers, I do not believe browsers have significant problems with XML-compliant HTML. Even if some tweaks to the output are necessary, an HTML-aware templating engine can do this automatically. XSLT is a well-known example of an XML-based templating language with support for HTML output.

You also base this argument on the supposition that such an obsession with XHTML exists more among users of ZPT or Genshi than, say, Django templates or Mako. Is this true?

While the argument against restrictions is intuitively appealing, note that arguments in favor restrictions are frequently made as well in debates surrounding Python programming. In Python for instance you cannot add a string to an integer, and people are generally happy that Python has a restriction here. More analogous with this debate, people from other languages frequently argue against the restriction of significant indenting in Python.
Anthony Briggs comments...
Wed, 17 Oct 2007 by anthony
Richard
XML-only templating engines only restrict choice and thus cause web developers unnecessary pain.

According to the front page of Genshi-*, it's quite capable of generating HTML 4.01, so I don't think it's such a big deal. In the worst case, you can generate xhtml, and serve it up as html-transitional :>


* - "Independence from a specific serialization format lets you instantly switch between generating well-formed HTML 4.01 and XHTML 1.0 (or other formats).", which links to http://genshi.edgewall.org/wiki/Documentation/streams.html#serialization


Return to debate