Not much nonsense, old irons! Get to work!
Install flask library
pip install flask
If the installation fails, you can try the following
pip install Flask
Problems encountered flask error solutions address
Go directly to the code to understand
from flask import Flask
import json
app = Flask(__name__)
# 只接受get方法访问
@app.route("/", methods=["GET"])
def check():
# 默认返回内容
return_dict = {
'return_code': '200', 'status': '处理成功', 'result': False}
# 赋值参数
name = 'soubei'
age = 18
# 对参数进行操作
return_dict['result'] = tit(name, age)
return json.dumps(return_dict, ensure_ascii=False)
# 功能函数
def tit(name, age):
result_str = "%s,老铁今年%s岁" % (name, age)
return result_str
if __name__ == "__main__":
app.run(debug=True, port=5050, host='127.0.0.1') # 指定端口,根据自己需求:host,0.0.0.0代表不管几个网卡,任何ip都可访问
Effect picture