Disable Jinja2 Template Cache

I am trying to disable the Jinja2 template cache. I looked around a bit and found that there is a cache_size parameter for the jinja environment. I am using the following:

 app.jinja_env = jinja2.Environment( cache_size = 0, loader = jinja2.FunctionLoader(utils.load_template) ) 

I use a custom bootloader to dynamically load domain-based templates (the application serves multiple domains). Unfortunately, using this, it looks like it is overriding Jinja's default filters and built-in functions - using

 @app.route(...) def page(): render_template('template') # from flask import render_template 

I get an UndefinedError: 'url_for' is undefined error UndefinedError: 'url_for' is undefined . What is the right way to do this?

+6
source share
1 answer

Instead, you can set app.config['TEMPLATES_AUTO_RELOAD'] = True . Instead of disabling the cache, it reloads the templates if the cached version no longer matches the template file.

+18
source

All Articles