Home Login Create account Contact Help
Close

Login to your account

Other Options

Comments feed

In response to Practicality versus Purity in Python templates

There are a number of very powerful template languages available in Python. Some template languages, such as Genshi [genshi.edgewall.org], allow complex Python statements and even full Python code within the template file. Others, such as Django [djangoproject.com] templates, prefer to restrict templates to presentation only and do not allow general Python expressions within the body of the template.

In the context of a web framework, is it better to have the full expressiveness of Python, or restrict templates to presentation only?

...

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

[code python]

print "Hello, World!"

[/code]



Glyph Lefkowitz argues for "Expressive Python"
Thu, 28 Feb 2008 by glyph
Rank 3. Average -1.0 ( 3 votes )

Templates are Python programs to generate HTML output. Just because they provide a convenient syntax for outputting large blocks of text doesn't mean they should cripple the expressive power of the language. If I want to write a "for" loop in a template, why should I have to mark up a section of my template with some weird, custom tags, and then write the actual "for" loop somewhere else that's hard to find?

Lennart Regebro comments...
Fri, 29 Feb 2008 by regebro
How do you mean that templates are python programs? You can't run them in a python interpreter...
Christopher Perkins comments...
Fri, 29 Feb 2008 by percious
According to Lennart Regebro:

How do you mean that templates are python programs? You can't run them in a python interpreter...



A ha! You forget about kid, which compiled your template into a .pyc which was in fact readable by a python interpreter. I dont know whether or not Genshi does this...
Lennart Regebro comments...
Fri, 29 Feb 2008 by regebro
PYC-files are indeed written in a byte-code language.That language is not Python. And neither is the templates.


Return to debate