How to implement context_processor or middleware for tornado python framework? I'd like to add common variable to base.html template. 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.