[Django]-Alternatives to the default django template system

5👍

Jinja2 is very much like Django templates: http://splike.com/wiki/Convert_Django_Templates_to_Jinja2

Mako is very much NOT like Django.

Try these two and see what approach you like best.

3👍

Maybe jinja2: http://lethain.com/replacing-django-s-template-language-with-jinja2/

Why do you want to replace it? It is very powerful and has so much built in support. I would think you would want to replace it if you already had a specific template system in mind.

👤jdi

1👍

Jinja2 is the most popular replacement I know of. The biggest difference is that it allows you to put significantly more logic and code into your templates: Django’s templating system is deliberately restrictive in this regard.

I have used Jinja2 and have to say I personally prefer Django’s template system, simply because it encourages a cleaner style where as much processing as possible is done in the view code, making refactoring and testing easier.

As for performance, there is a section in the Jinja2 FAQ which claims Jinja2 and Mako are roughly equivalent, and both about 20 times faster than Django’s template renderer, but also points out that such benchmarks are all but meaningless.

1👍

Coffin project contributors are trying to build a complete drop-in replacement for Django Template. Coffin api loads Django Filters and tags for you, so you can enjoy Jinja templating and use existing Filtes and Tag Libs written for Django.
Coffin project is actively maintained. You can read more reference here:

  1. justcramer.com/2009/09/14/using-jinja2-with-django/
  2. matthowell.com/blog/2011/03/02/integrating-jinja2-and-django/

0👍

I don’t use templates at all, preferring a pure python OO approach.

To be able to do this I code a small but useful library in Python, that let me generates any mark-up code.

I could say that the experience is somehow similar to the one you can have with a tool such as QT… obviously, my tool is way smaller than a vast tool like QT, there are some similarities, especially in the use of classes and the Composite pattern.

I think many people will dislike my approach. However, if you want to take a look, here is the link to the code:

Pytml framework

0👍

https://pypi.org/project/yawrap/
Templateles, pure pythonic html generator. It’s fast, has no dependencies, runs on python 2.7, 3.x and pypy.
Outputs ideally indented html code with zero overhead (indents for free).
No need to use tags or filters from django, because you already have absolutelly everything in python.

Leave a comment