Why you might hate the template system in django
Posted on October 26th, 2008 in Programming |
Okay first of all I did try hard to love it but there are just so many annoying things about it that i really don’t like and here are some of them:
1) They have so many if statement that actually brakes the beauty of python, so you have if, ifchange, ifequal, and ifnotequal. Instead of just doing something like
{% if thisVariable == thatVariable %}
2) You cannot pass multiple arguments to custom filter, you can only pass 1 or 2 arguments, i don’t know what they were thinking when they decided this, but i hope they fix this quickly coz not all of time you only have to pass 1 or 2 arguments. (http://code.djangoproject.com/ticket/1199)
3) Templates are so strict that you cannot use underscore on an object. While this is good in terms of security and design, it adds up to your production time. Solving this would bring us to the next number
4) You need to use filter even if you don’t like to, say you just like to compare 2 numbers, ideally if #1 would be followed then its {% if a > b %} but nope, you have to do it on your custom filter. See everything that is not on the build-in filters of django you have to do it on your own even if that feature is part of python.
5) You cannot have 0 arguments on filters, say you just want to check if something is logged in or not, you cannot call the filter with {{ is_login }} but you need to pass a dummy argument like {{ 1|is_login }}
Now i know im just new with django but this stuff makes me feel that i’m not using python anymore, i say this when compared it to other templating system like smarty. Its a template engine but somehow you still feel that your using php. I hope django fix their template system













2 Responses
I think you nailed it in one with this: “…this stuff makes me feel that i’m not using python anymore…”
Actually, that’s precisely true: Django’s template language is specifically designed to be lightweight and simple, for designers, not programmers (see http://docs.djangoproject.com/en/dev/misc/design-philosophies/#don-t-invent-a-programming-language). In other words, its optimized for real-world teams where there’s a division of labor between the backend developers and frontend designers.
However, that means that Django’s template language specifically isn’t designer for people who expect the full power of Python in their templates. Sounds like you’re one of those folks; I’d suggest giving another template language a try — any Python template language will work just fine with Django. Jinja is an offshoot off Django; it’s got similar syntax but a lot more power. Or you might like Cheetah; a lot closer to raw Python than anything else.
Good luck!
I definitely agree with the statement that a template system should not be a programming language but you have to take a look on the fact that even stuff like less than, greater than, passing none or multiple stuff from template to program is not present, what i’m trying to say is that even if they are designers they do have basic mathematic knowledge and if you have integrated with a designer, you pretty much know that not 100% of the time designer just design a site but programmers must/do still need to add logical/programming kinda like thing inside a template. Having said that they must at least make it a bit easier for programmer to do their stuff.
Thanks for your suggestion, ill try Jinja or Cheetah later on, thanks.