Login to your account |
Other Options |

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]
I think allowing Python code directly in a template is a good thing, and in fact, I refuse to use any templating engine that does not allow it.
I believe in the MVC paradigm, and being able to put code directly into your View keeps a lot of garbage out of your controller. Take for instance the concept of pagination. In reality, I just want my template to understand, the current page, how many records per page, and how many records there are in total. The View should be able to figure out how that information should be rendered. Doing these kind of manipulations without a block of python code gets to be pretty tedious and difficult, but if you move the logic for viewing the links for pagination into it's own block it becomes much more understandable and readable.
In summary, any time you have a view which needs more complex algorithms to render, having a python block is not only useful, but preferred.