from flask import Flask, request
from log_utils import logger
app = Flask(__name__)
# get
@app.route("/login/", methods=["get"])
def hogwarts():
logger.info(f"请求参数为{request.args}")
result = request.args
a = result.get('a')
b = result.get('b')
print(a, b)
return {"code": 0, "msg": "get success"}
# post请求的json数据
@app.route("/regist", methods=["post"])
def post_regist():
logger.info(f"请求参数为{request.json}")
return {"code": 0, "msg": "post success"}
# form表单
@app.route("/put", methods=["put"])
def put_regist():
name = request.form.get('name')
p = request.form.get('password')
email = request.form.get('email')
logger.info(f"请求参数为{request.form}")
logger.info(f"name:{name},password:{p},email:{email}")
return {"code": 0, "msg": "post success"}
# 文件上传
@app.route("/file", methods=["post"])
def post_file():
obj = request.files.get("file")
logger.info(obj)
filename = obj.filename
logger.info(f"文件名为:{filename}")
# 将接口接收的文件保存在本地
obj.save("./1.txt")
return {"code": 0, "msg": "post success"}
if __name__ == '__main__':
app.run()
评论