resource.py 文件源码

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

项目:saas-api-boilerplate 作者: rgant 项目源码 文件源码
def register(cls, api):
        """
        Add this class as a resource to the flask app/blueprint.
        :param flask.Blueprint or flask.Flask api: API to add this class to as a MethodView.
        """
        view_func = cls.as_view(cls.__name__)

        # Route for Model details by identifier (Read, Update, Delete by identifier)
        # kwargs conversion to flask with int converter. This is a bit ugly.
        # http://flask.pocoo.org/docs/0.12/api/#url-route-registrations
        details_endpoint = cls.schema.opts.self_url.format(id='<int:model_id>')
        api.add_url_rule(details_endpoint, view_func=view_func, methods=('DELETE', 'GET', 'PATCH'))

        # Route for Model Resource without identifier (Create, and possibly Read list)
        methods = ['POST']
        if cls.schema.opts.listable:
            methods.append('GET')
        api.add_url_rule(cls.schema.opts.self_url_many, view_func=view_func, methods=methods)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号