简体   繁体   English

龙卷风框架的context_processor

[英]context_processor for tornado framework

How to implement context_processor or middleware for tornado python framework? 如何为tornado python框架实现context_processor或中间件? I'd like to add common variable to base.html template. 我想在base.html模板中添加常用变量。 Without change all handlers bases classes. 没有改变,所有处理程序都基于类。

It can be done like this: 它可以这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM