安装flask-restful from flask import Flask from flask_restful import Resource, Api app = Flask(__name__) api = Api(app) //封装app class HelloWorld(Resource): def get(self,todo_id): return {"name":"alex"}
def put(self,todo_id):
pass
api.add_resource(HelloWorld,'/<string:todo_id>') //路由,资源和url建立映射关系
一种资源只能添加一次,#url匹配到http://127.0.0.1:5000/todo.?
if __name__ == "__main__": app.run(debug=True,host="0.0.0.0")