Is there a way to change the Jinja2 root directory per-request on Flask? Right now I do:
app.jinja_loader = FileSystemLoader(t开发者_StackOverflowemplate_directory)
but it seems to work only once per process (the process chooses the correct directory at first and then stays there, no matter how many changes I make)...
It turns out that a Jinja caching bug is preventing the correct template from loading, so disabling the cache works:
app.jinja_env.cache = None
You can try this:
app._get_current_object().jinja_loader = FileSystemLoader(template_directory)
Docs http://flask.pocoo.org/docs/api/#notes-on-proxies or http://werkzeug.pocoo.org/docs/local/#werkzeug.local.LocalProxy._get_current_object
精彩评论