flask-restful 初探

flask-restful 是 Flask 的一个用于支持 RESTful 的插件。

刚开始用对我来说还是比较坑的。。。

目录结构

/

    /test

    /test/common

           /__init__.py

    /test/resources

           /__init__.py

           /test.py

    __init__.py

    app.py

README.md

坑1:导入包

在app.py里头摸索出来

from resources.test import Test

坑2:字符串路由参数

api.add_resource(Test, '/Test', '/Test/<thestr>')

对应到Test类就

from flask_restful import Resource

class Test(Resource):
    def get(self, thestr):
        return {'return':"id: %s" % thestr}
    def post(self, thestr):
        pass

真是nice呢。。。

猜你喜欢

转载自www.cnblogs.com/sinx/p/10886773.html