54đź‘Ť
While it’s just my own experience, I found converting from Django to Jinja2 to be worthwhile for the following reasons:
- The design and implementation of Jinja2 seemed more intuitive to me, both as a software developer and template designer;
- Jinja2 is more extensible (at least in the ways I’ve sought to extend my template engine);
- Jinja2 is more flexible in terms of permitting logic-code to be run (but it gives you enough rope to hang yourself with);
- Jinja2 is regarded as significantly faster (though I haven’t done any benchmarks, this is always subject to debate depending on the tests used, and in any event largely irrelevant in the total wait time for a query that has to do DB lookups);
Jinja2 gives significantly more helpful error output than Django (i.e. traces to the line number in the template where the error occurred).Edit: According to Dor’s comment, Django gives helpful error messages that point to the line and context of a problem, much like Jinja2.
If you haven’t had any trouble with Django’s template engine, Jinja2’s should feel relatively intuitive, if perhaps a bit more polished (or it did to me, at any rate). As well, I found the Coffin
project well written and reasonably helpful when converting from Django to Jinja2 – both for its use, and as an example of how to extend Jinja2.
All that being said, Django’s template engine is solid and quite capable for most tasks. I believe it’s being improved in the next revision of Django, and there is quite a lot of effort to add to its capabilities by quite a number of dedicated developers. As a result there are no worries of it becoming unsupported in the near to medium-term future.
Again, that’s just my experience, for what it’s worth – I hope that’s helpful.
4đź‘Ť
There’s also django-jinja. https://github.com/niwibe/django-jinja
New and nice project. http://niwinz.github.io/django-jinja/latest/
It claims to be a simple and nonobstructive jinja2 integration with Django.
- [Django]-Error: "dictionary update sequence element #0 has length 1; 2 is required" on Django 1.4
- [Django]-How do I convert a Django QuerySet into list of dicts?
- [Django]-Python MySQLDB: Get the result of fetchall in a list
3đź‘Ť
From what you have said, it’s may not be worth the trouble to migrate to Jinja2. There are filters in Django Templates which could help you do any math operations.
Regarding list operations, what exactly are you talking about? If you want some particular list operation to be supported in Template, than write a custom filter.
There are also some existing 3rd party math filters for Django.
If you think about it, it’s by design that Django templates does not have too much of “programming constructs” in them. HTML templates should be such…
- [Django]-Django aggregate or annotate
- [Django]-Use variable as dictionary key in Django template
- [Django]-Converting Django QuerySet to pandas DataFrame
2đź‘Ť
Two projects which are trying to integrate Jinja in Django with simple integration steps and nicely hooks with Django –
I am integrating them right away to experiment if they work too with Django contrib apps like Django Admin. But I feel, it will be available for project apps and Django default template system will be used in internal apps like Admin.
- [Django]-How to detect Browser type in Django?
- [Django]-How do I prevent fixtures from conflicting with django post_save signal code?
- [Django]-Uwsgi installation error in windows 7