测试平台后端开发公开课

流程

安装核心插件

pip install flask
pip install flask-restful
pip install flask-sqlalchemy
pip install pymysql
pip install flask-jwt-extended

直接启动

if __name__ == '__main__':
    app.run(debug=True)

相关链接

https://flask.palletsprojects.com/en/1.1.x/

https://flask-restful.readthedocs.io/en/latest/quickstart.html#

https://flask-sqlalchemy.palletsprojects.com/en/2.x/

https://flask-jwt-extended.readthedocs.io/en/latest/

https://flask-cors.readthedocs.io/en/latest/

from flask import Flask, request
from flask_restful import Api, Resource

app = Flask(__name__)
api = Api(app)

db={}

@app.route('/')
def hello_world():
    return 'Hello, World From ceshiren.com !'


class TestCaseService(Resource):
    def get(self):
        name = request.args.get('name')
        return f"testcase {db[name]}"

    def post(self):
        name=request.json.get('name')
        db[name]=request.json
        return f"testcase {name} create success"

    def put(self):
        pass

    def delete(self):
        pass


api.add_resource(TestCaseService, '/testcase')

if __name__ == '__main__':
    app.run(debug=True)

关闭