gevent

Jinja2 vs Tenjin: Why I moved (back) from Jinja2 to Tenjin

Jinja2 vs Tenjin: The Story

I started a new project: for learning purposes: to learn python gevent api and to implement a simple server – with Authentication & Websockets.

First thing after handling routings and starting server with the famous ‘hello, world!’ message was to find a suitable Framework, if any.

After a search I found Bottle which I think is amazing microframework. Flask was also great, but I loved the idea of a microframework without template engine so I could choose my own.

As I worked with many Template engines in many different languages and environments (.NET/Ruby/Node.js/Python/PHP/and more). I know I can handle any syntax, so the first thing I’ve looked for is the fastest Python template engine.

I’ve choosed to try Tenjin, It worked great, looked bad. the syntax was messy, there was that .cache file near my.pyhtml files… But it worked great and FAST!

I’ve got to admit that SpitFire catched me, and I’d choose it for several reasons:

  • Really FAST!!
  • Trivial Cheetah templates will probably compile in Spitfire

But as I ‘m not using Cheetah and the Languages support Tenjin offers – for me It is Winning case for Tenjin.

 

Jinja2 vs Tenjin

I decided to try more template engine, slower – but friendly : Jinja2.

Tenjin syntax , which was somewhat ugly, and Jinja2 was just beautirful, and reminds me Django’s and Twig which I like… So, I;ve decided to try Jinja2 and to feel the difference.

Found no problems there, Jinja2 was working great, and the .html files are looking great in compare to Tenjin,.. more readable, no .cache file – and .html instead of .pyhtml. I’ve choosed to stick with Jinja2… for now…..

…meanwhile.. on another project I’m working on in Django, I’ve tried to implement Googles AngularJS and found my self in a very bad situation. the AngluarJS Template Engine was similar to Django’s one! There are several solutions and fixes for this, some are really messy but I fixed it… and I’ve learned a very important lesson… Templates engines used today in both sides: both client & server, and this should be taken into consideration when choosing template engines.

The true title of this article should be: Why I moved from Tenjin to Jinja2 and why I moved from Jinja2 to Tenjin again..

As Jinja is very similar to Django (and angular) I found my self thinking about Tenjin again…

  • It’s faster then Jinja.. it’s faster then most teamplte engines!.. ,
  • it support many languages which make the project more trasferable and convertable between servers (Supports PHP, Perl, Ruby & Python).
  • It supports JS templating – wchich I haven’t tried yet,
  • It’s different then the mainstream template engines with {{ }} and {*  *} so mixing Template engines with client side template engines should be safer.

  

Summary

I know it’s not a classical -vs- article which compares between features, and there is a lot to cover in the topic of jinja2 vs tenjin and the feautres of both,.. I choosed to wrote instead on my view and decisions… what made me go back to Tenjin and leave Jinja 2 behind.. This is my story of Jinja2 vs Tenjin… In my case, Tenjin won, but I MUST say that Jinja2 is GREAT!, also: SpitFire, Mako Template, Cheetah, Genshi & others… as always: each tool for different task… It’s your call…

 

 EDIT:

I learned about Jinja2 inheritance feature which is missing in Tenjin. If you need Template Inheritance go for Tenjin (or other).

 

What do you think? Which Python Template engine do you use? and why?

Development Specialist, Artist and Activist
Personal Website

Leave a Reply

Your email address will not be published.


*