Disable Template Cache Jinja2
11,602
You might want to set app.config['TEMPLATES_AUTO_RELOAD'] = True
instead. Instead of disabling the cache, it will reload templates if the cached version no longer matches the template file.
Related videos on Youtube
Author by
Tyler Sebastian
Updated on November 12, 2020Comments
-
Tyler Sebastian almost 3 years
I'm trying to disable Jinja2's template cache. I've done some looking around, and I've found that there's a
cache_size
parameter for jinja's environment. I'm using the following:app.jinja_env = jinja2.Environment( cache_size = 0, loader = jinja2.FunctionLoader(utils.load_template) )
I'm using a custom loader to dynamically load templates based on the domain (the app serves multiple domains). Unfortunately, using this, it looks like it overrides Jinja's default filters and builtin functions - using
@app.route(...) def page(): render_template('template') # from flask import render_template
I'm getting a
UndefinedError: 'url_for' is undefined
error. What's the proper way of doing this?