龙卷风没有执行祖先的准备

时间:2018-08-31 04:42:43

标签: python tornado

我使用龙卷风编写的代码由处理基本JSON操作的基类TbHandler组成,它是后继ApiLoginHandler

但是当我将json发布到ApiLoginHandler时,没有调用TbHandler的prepare

这是我的祖先班

class TbHandler(tornado.web.RequestHandler):
    def __init__(self, application, request, **kwargs):
        super(TbHandler, self).__init__(application, request, **kwargs)
        self.response = dict()

    def prepare(self):  ## <- expected of position breakpoint
        if 'content-type' in self.request.headers and \
         ...

然后,下面是TBHandler的继承人

class ApiLoginHandler(TbHandler):
    def initialize(self, process):
        self.process = process

    async def post(self):
      if "username" not in self.request.arguments:
          reason = 'invalid request: missing username'
          self.set_status(400)
          self.finish({"reason": reason})
          return

将json发布到api时

  

curl'http://localhost:5000/api/auth/login'-H'接受:   application / json'-H'内容类型:application / json; charset = UTF-8'   --data-binary'{“ username”:“ admin”,“ password”:“ ehllow”}'

响应为{"reason": "invalid request: missingusername"}

我期望的调用顺序如下,但是未调用prepare()。
1. TbHandler :: init ()
2. TbHandler :: prepare()<-未被称为
3. ApiLoginHandler :: post()

我错了什么?

0 个答案:

没有答案