Why Jinja is not Django and why Django should have a look at it
lucumr.pocoo.org
lucumr.pocoo.org
If you don't need template tag libraries, Jinja2 is the obvious choice. If you do, however, then good luck. Django Template custom tags are easy to implement, even if you are not using the decorator helpers.
Jinja2 custom template tags are, to quote their website "non-trivial" to implement, and so poorly documented that you are stuck trying to figure out how the tags work from source.
In my CMS I have a number of tags which I make available to my users (for things like named content blocks, menus, named images, etc.). I attempted to migrate my tags to Jinja2, but finally gave up. With proper caching, Django templates are good enough.
Jinja tags are harder to grok, but after that they are starting to make sense.
In my example, a CMS for Pete's sake, there is a very real and pervasive need for custom tags that are in no way obviated by Jinja2's architecture. Jinja2 is a great developer template library, but, as a previous poster noted, a very poor Designer library. I code my platform for Designers. So do a whole lot of other CMS programmers. So this line of reasoning, while accurate, is moot.
Poorly documented?
http://jinja.pocoo.org/2/documentation/extensions#module-jin...
I agree that the parser API is not exactly pretty - but creating your own tag starting from that example is pretty straightforward. I have created many tags myself (mostly the standard case of mutating the enclosed content in one way or another) and can't complain. It took me literally minutes to get my first tag working - perhaps you are referring to an older version of jinja?
My reasons for choosing Django templates over pretty much anything comparable. Everything else tries to make things easy for developers, Django templates makes things easy for designer.
Even if we had designers, I'm not sure they should be writing templates. I'd rather they be writing CSS and that the dev team be responsive to template change requests. If a designer needs a div or span or move some stuff around into a table, they should be able to handle basic template manipulation in any language... and those changes need to be code reviewed by a developer anyway.
On a related note, I just wish there a more mature Haml implementation for Python. We use SASS and love it, but Haml is strongly tied to Ruby. GHRML doesn't seem to be well supported or maintained.
Django is no longer a newspaper-centric framework. Far more users of Django want a hacker-centric template language. Markdown and other markup languages are far closer to the needs that the Django template language once filled.
But Markdown doesn't fit the 'newspaper' usage model in anywhere near the same way -- Django templates let the writer do all kinds of layout fuckery in an idiot-proof, dev-supported, maintainable, extensible, {%benificent_adjective%} way.
Even if we had designers, I'm not sure they should be writing templates.
I've never understood this attitude. Maybe it's just because I've worked for places which seek out talented people who know their stuff, but it feels way too much like unjustified territoriality on the part of developers.1) To make it designer friendly
2) To force you to put logic into back one layer
If you have talented folks, #1 shouldn't be a concern. Any technical artist should be able to learn enough of any template language to be trusted to not break things. Just as one coder has to code review the work of another, someone should code review the designer's work. Maybe that's a developer, maybe it's a senior technical artist; it doesn't matter. Choosing the right tool for the right people puts a lot of trust in the fact that you choose the right people!
#2 is idealistic bullshit. There is HTML-specific view logic. If you have a view which fetches some data, that same view should be re-usable for an API as json or xml or whatever you choose. But imagine the case were you have an "Export to CSV" button. That is simply two different templates over the exact same data. The HTML version might need to do some smarts about grouping or human-readable adjustments. There will surely be some javascript that depends on particular elements and structure. Forcing all of that logic into template tags is just silly.
If you have talented folks, #1 shouldn't be a concern.
On the contrary; we don't expect programmers to master design and become Photoshop gurus, for example, so why should we expect designers to master what is, essentially, programming? There's a lot to be said for having different groups of people whose strengths are in particular domains. If you have a view which fetches some data, that same view should be re-usable for an API as json or xml or whatever you choose.
Actually, this only works in the most trivial (and thus non-real-world) of situations. Usually, API access needs to be mediated through additional logic (authentication, access control, rate limiting, etc.). Forcing all of that logic into template tags is just silly.
I have to admit that I don't really know what you're getting at here. If you do have a case that's as simple as "use another template", well, you use another template. If you don't, no amount of program logic in templates is going to save you.Anyway, here's how I see it:
1. Django's template language is designed to permit enough logic to handle presentation, and to be easily extensible for cases where you need something more.
2. Jinja is designed to permit quite a lot of free-form programming constructs, and is not particularly easy to extend when you run up against a wall.
These are fundamentally different approaches to "templating", and what I've found is that people who prefer, say, Jinja tend to just use it and move on. The people who stick around to argue are the ones who think that some particular tag or extra bit of logic should be made available by default in Django, and so are arguing about differences of degree rather than differences of kind.
It makes me wonder if http://lucumr.pocoo.org/2008/9/16/why-jinja-is-not-django-an... is using the speedups or not. It seems that 400 ms might be slow with them all enabled...