[Django]-Is there a reason I should be dissuaded from using an alternative templating engine in my Django app?

4đź‘Ť

âś…

I’ll be honest, I didn’t thoroughly read the responses. But I’m guessing it’s a lot of “no python in your templates” and “your view shouldn’t have much logic” type stuff.

If you put idealism aside and opt for pragmatism then I think Mako is a fine choice. I’m using it in a production capacity (mainly for speed, power and dynamic inheritance) for 3+ years now. It hasn’t failed or been otherwise annoying in any way.

The idealists are correct, but sometimes you have to go for what’s doable vs what’s right. If you are not limited by the Django templating engine use it. If you need more power, Mako and Jinja are fine choices.

Django makes it very easy to swap out templating engines and keep most things working as before:
http://docs.djangoproject.com/en/dev/ref/templates/api/#using-an-alternative-template-language

👤Xealot

3đź‘Ť

Executing arbitrary code in templates should not be considered an inherently good thing. Taking advantage of such functionality is usually a sign that your architecture is broken.

That said, if you read the Django documentation, it explicitly says that you should feel free to use, discard, and replace any components you wish. Django is intentionally modular, and in fact, the two most trivially-replaceable components are the templating engine and the ORM.

If you want to use Mako instead of the Django templating engine, just use Mako.

2đź‘Ť

The one reason I’d refrain from using jinja, Mako or anything else is that it may not make your app future proof with django enhancements.

There was a GSoc project proposal last year, by Alex Gaynor to make the template loading fast. – It was then retracted in favor of NoSQL project.

But with many more core developers and faster clearing of tickets, I’d stick to django full stack, knowing fully well, that components have to be changed to by home grown ones eventually.

If you are really looking for a glue framework on awesome python libraries, including the ones you choose, Flask is out there.

👤lprsd

1đź‘Ť

addons.mozilla.org is using Django + Jinga: https://github.com/jbalogh/zamboni

Not sure whether or not the community frowns on Jinga, but many people like it, as an example.

0đź‘Ť

If you did mean “app”, rather than “project”, and it’s not for entirely private use, I would recommend that you not change the template engine; it will make the app much less likely to ever be used by anyone else as it’ll require them to alter some core settings, and it may break interaction between it and other apps or the project as a whole.

👤Chris Morgan

0đź‘Ť

Your example reminds me of the old PHP days when people would mix PHP with html all over the place. Felt really powerful. Until one day people realized that the mess is unmaintainable.

If the design is chopped up into “functions”, will a designer understand it then? It will probably annoy him.

👤Kugel

Leave a comment