It’s considered a good practice to enable template caching in Django. It saves on the overhead of loading and parsing templates and turning them into template objects, which can give a nice performance boost when repeatedly rendering the same templates.
Currently it’s possible to enable template caching by using the cached loader. To do so you’ll need to add the loaders option to the engine settings and set it to a nesting of lists/tuples (I’ll wager no one can get this correct on the first try without first consulting the docs). This makes enabling template caching needlessly hard, and the discoverability of this feature lower than necessary. To this day I run into developers who have worked with Django for years but are unaware of the cached loader.
One of the downsides of enabling the cached loader is that it will cache templates until the server is reloaded. This makes it ill suited for development. I have, on many occasions, seen developers (including myself) forget to turn off template caching in their local settings, resulting in lost time trying to figure out why their changes are not showing.
It would also be useful to have caching enabled in development so the template loading behaviour is (mostly) the same in development as it is in production.
Another reason is that the performance of template rendering will be roughly the same development as in production, which can make a great difference if you’re working with complex templates and/or custom tags that perform expensive operations in their __init__.
With caching and auto reloading as a core feature of Django’s engine it will be (somewhat) on par with the alternative Jinja2 engine shipped by Django. Jinja2’s Engine lets you configure an Environment (
http://jinja.pocoo.org/docs/dev/api/#jinja2.Environment) using the engine's options. This includes setting a bytecode_cache and enabling auto_reload (this last option mirrors DEBUG by default in Django).
So in short, I propose making template caching a true feature of Django’s template engine. Which can be configured in a way similarl to the Jinja2 engine (and could be on by default for new projects):
TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True
'OPTIONS': {
'cache_templates': True,
'auto_reload': DEBUG // this could be the default set by the engine
}
}]