开发者

Is there a way to change the Jinja2 template loading directory per-request?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜