class BaseHandle(object):
def intialize(self):
print('初始化方法')
def get(self):
raise Exception('405')
def post(self):
raise Exception('405')
def on_finish(self):
print('请求结束')
class IndexHandler(BaseHandle):
def intialize(self, conn):
print(conn)
print('调用子类的初始化方法')
def get(self):
print('调用子类的get方法')
if __name__ == '__main__':
# 配置路由
urlpatterns = [(r'/', IndexHandler, {'conn':'123'})]
# 设置请求地址
action = '/'
# 设置用户的请求方式
method = 'get'
for url in urlpatterns:
p, c, d = url
if action == p:
index = c()
index.intialize(d)
getattr(index, method)()
index.on_finish()
python tornado RequestHandler的底层原理
最新推荐文章于 2022-11-05 21:09:47 发布