Django 1.2 introduced a new template loader, that stores data in cache ( django.template.loaders.cached.Loader
).
Unfortunatly, i failed to find any info on how the cache is invalidated and when and how it is reset.
I want to use this on my server, but i'm not sure, that it would reset on django restart (that would be enough for me).
from django.template.loader import template_source_loaders
def reset_template_cache():
if not template_source_loaders:
return
for loader in template_source_loaders:
loader.reset()
There you go :)
The existing solutions written here broke around Django 1.9, due to the template loader system having been refactored. If you try to use the code that imports template_source_loaders
and that import fails, try this:
from django.template.loader import engines
for engine in engines.all():
engine.engine.template_loaders[0].reset()
This code assumes that your TEMPLATES
setting is using the default 'loaders'
option, or using only a single django.template.loaders.cached.Loader
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With