Template language for Django

March 02, 2008

That’s true, I’m finally learning Django. Since I haven’t had no big website until now, I’ve been using my microwebframework pungi. But for large websites I feel the need for something more powerful and scalable.

I’ve been following (well, almost) the tutorial on the website adapting it to my needs. I’ve now reached the template part and I wondering if Django’s default template system is the best approach. I am pretty familiar with HTML and I even find it natural to write using XML tags, but I’m not sure if this is the best approach.

I’ve been looking for some alternatives (Yeah, Django is great because you can use whatever template language you want without any trouble!) and I found Brevé, a python DSL (or little language) for HTML generation. Writing Python is so much simple than the weird XML syntax. But I’m already used to HTML, so I got a problem here. And I believe there would be a more pythonic way of representing HTML. I feel ruby’s HTML generation in the CGI module (scroll down to “Print http header and html”) more readable than python lists. But okay that’s just my personal opinion.

I also took a look at PyMeld. Not quite a template language, but a way of manipulating HTML, that would have the same effect, but I believe Django’s template system is easier.

I could also use a client-side javascript template system, like MV suggests but I think neither me nor the world is ready for such thing.

So what would you choose if you were me?

Tagged with: en, python, django, templates, webdesign
This post has 6 comments. Feel free to read them and leave your own.
Check out the Mako template library - http://www.makotemplates.org/ .

It is Pylons' default templating engine. And it rocks!

I've used some template languages in the past
(mostly on the php and java worlds), and to this moment I find
Django's to be the one that least gets in the way and, when it
does, it does for the right reasons (ie, to stop me from mixing in
the html more logic than what it was really needed).



So, to answer your question, I guess I'd stick with django's template language ;)

João, Mako is very similar to Django's one, so I see no big advantage :/ I guess I'll stick to that one. I can't do webdev without HTML at the moment...
Django template system fits your needs.
Besides, it has integration with all kinds of things in django. Such as generic views etc. Also you have a lot of snipets in here http://www.djangosnippets.org
For your microframework I would suggest Mako or Jinja(uses the same syntax of Django template system).
To me the best choice was brevé. It is a pure python template engine: you can have python constructs in there. That is the main advantage. I find the brevé templates ending being very concise and easy to read. Some work has to be done though to use django with brevé.
Have you checked out Tenjin? http://www.kuwata-lab.com/tenjin/

It's the fastest template engine there is, written in pure python. It's HTML compliant, but still gives you full access to python.

FYI - Mako's advantage is its speed. It's quite a bit faster than Django if you tell it to cache it's generated templates as compiled python. Also, Mako gives you access to all of python as well. Django does not.

Comment:

Author:
Email:
Website:
Comment:

About

I used to write in this blog, but I've found a better format to express myself. From now on, you may read my writings on ideas, programming and politics on my new wiki.

hCard

Name: Alcides Fonseca
Email:
MSN:
Gtalk:
Nov 24, 1988 40.197958, -8.408312

Tagcloud

Archives

Other links