Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Template Cache Jinja2

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?

like image 326
Tyler Sebastian Avatar asked Jun 01 '16 17:06

Tyler Sebastian


1 Answers

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.

like image 131
Petr Viktorin Avatar answered Oct 17 '22 01:10

Petr Viktorin