I've got a couple small (500 or 600 lines of template code) Django sites, and I'd like to migrate them to using Jinja2… But I'd like to get some idea of how much work it will be. So, in general, about how much work is it to migrate a small Django site to Jinja2? And is it “worth it”?
Django sets Jinja with two default behaviors, one for when DEBUG=True -- a common setting in development -- and the other for when DEBUG=False -- a common setting in production. If DEBUG=True and an invalid variable is set in a Jinja template, Jinja uses the jinja2.
The Jinja template engine allows customization of tags, filters, tests, and globals. Also, unlike the Django template engine, Jinja allows the template designer to call functions with arguments on objects. Jinja is Flask's default template engine and it is also used by Ansible, Trac, and Salt.
Jinja2 works with Python 2.6. x, 2.7. x and >= 3.3. If you are using Python 3.2 you can use an older release of Jinja2 (2.6) as support for Python 3.2 was dropped in Jinja2 version 2.7.
Jinja supports dynamic inheritance and does not distinguish between parent and child template as long as no extends tag is visited.
While it's just my own experience, I found converting from Django to Jinja2 to be worthwhile for the following reasons:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With