gpt4 book ai didi

python - tornado 框架的 context_processor

转载 作者:太空宇宙 更新时间:2023-11-03 14:31:55 25 4
gpt4 key购买 nike

tornado python框架如何实现context_processor或中间件?我想将公共(public)变量添加到 base.html 模板。无需更改所有处理程序基类。

最佳答案

可以这样做:

class MyHandler(tornado.web.RequestHandler): 
def render(self, *args, **kwargs):
kwargs['my_context_variable'] = 'context'
return super(MyHandler, self).render(*args, **kwargs)

关于python - tornado 框架的 context_processor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9224232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com