A friend and developer I respect recently advised that I avoid using ‘Includes’ in django templates. The sum of their argument was that includes are ‘evil’.
I am having trouble understanding the logic; My novice opinion is that they are a great way to organise chunks of reusable html, and instead of having to edit html in multiple locations I can simply edit it in one when changes must be made.
What do all you geniuses think? Please provide some Pro’s and Con’s of using includes in Django templates
It seems a slightly odd opinion. Includes are a perfectly valid part of the template language, have been so since day 1 and have never AFAIK been recommended against or deprecated.
Your friend might be trying to say that you should rely more on template inheritance (which is kind of an opposite include). That’s true as far as it goes – most of the time it’s better to compose your templates of blocks that override or extend ones defined in parent templates. But there’s definitely a use-case for includes.
The only other reason he might say that would be because of the added filesystem hit of loading include templates from disk. In which case, he’s definitely off the mark – again, the template inheritance model which definitely is recommended would have exactly the same hit; and both can be avoided by using the optional caching filesystem loader.