framework.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:Flask 作者: Humbertzhang 项目源码 文件源码
def rest_controller(cls):
    def replacement(environ, start_response):
        req = Request(environ)
        try:
            instance = cls(req, **req.urlvars)
            action = req.urlvars.get('action')
            if action:
                action += '_' + req.method.lower()
            else:
                action = req.method.lower()

            try:
                method = getattr(instance, action)
            except AttributeError:
                raise exc.HTTPNotFound("No action %s" % action)

            resp = method()
            if isinstance(resp, type("")):
                resp = Response(body=resp)
        except exc.HTTPException as e:
            resp = e
        return resp(environ, start_response)
    return replacement
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号