Python 如何使用init参数设置处理程序的tornado路由?
我正在构建一个tornado web服务器。其中一个处理程序需要init参数。如何设置路由列表以便传递参数值Python 如何使用init参数设置处理程序的tornado路由?,python,tornado,Python,Tornado,我正在构建一个tornado web服务器。其中一个处理程序需要init参数。如何设置路由列表以便传递参数值 class ActionHandler(): def __init__(self, p1, p2): self.p1 = p1 self.p2 = p2 async def post(self, action): x = self.p1 y = self.p2 # .... app =
class ActionHandler():
def __init__(self, p1, p2):
self.p1 = p1
self.p2 = p2
async def post(self, action):
x = self.p1
y = self.p2
# ....
app = tornado.web.Application([
('/action', ActionHandler) # How to pass init parameters?
建议您不要重写RequestHandler
子类的\uuuu init\uuu
方法。如果要将初始参数传递给处理程序,请使用
建议您不要重写RequestHandler
子类的\uuuu init\uuu
方法。如果要将初始参数传递给处理程序,请使用
class ActionHandler():
def initialze(self, p1, p2):
self.p1 = p1
self.p2 = p2
# then pass these arguments in a dict
# when you register the route
app = tornado.web.Application([
('/action', ActionHandler, {'p1': 'Hello', 'p2': 'World'}),
])