Django design philosophies DTL - confirm if should update

I absolutely agree that the roles have morphed over time, and the knowledge sets used have changed where the separation of duties lie.

But I look at this from a different perspective. It’s not a question of if certain things can be done in the template, but should they be done there - and my answer is a resounding no.

I personally am extremely happy with the limitations created by the DTL - and actually wish they were more restrictive.

I came to Django from working in environments using templating systems that were indistinguishable from the rest of the language or were even complete programming languages of their own - and the maintenance load of those systems was a nightmare. (The maintenance load of one of those systems was so bad that we actually got approval to do a complete rewrite of that system into Django. Two years and 120k+ lines of code later and we have what everyone agrees is a far superior system.)

Having felt first hand the pain of trying to figure out where the business logic for “X” was because someone decided to program it into a template is something I will never go through again.

I would much rather “jump through hoops” in my views to prepare the data for rendering than to permit it to be done in a template. At least I’ll know where to look for the code when it needs to be modified.

Yes, it might feel nice to do stuff like that now, but the “four-years-from-now you” - or the person who replaced you - will be cursing that decision.

So while the DTL may not be perfect, it’s closer than any other system I have used - and I’m extremely grateful for that.

Having said that, I also acknowledge (as I commented on above) the ability for developers to add tags and filters to provide any desired additional functionality.

If someone wants to do that for their projects, great. If someone wants to use another templating language, also great. (Django even provides Jinja2 for that purpose)

However, neither of those (when it comes to adding programmatic functionality to a template) will ever pass a code review that I’m a part of. That’s a personal and professional architectural decision I made about 10 years ago and have never encountered a reason to change it.

2 Likes