一,创建静态路由
from flask import Flask
app = Flask(__name__)
@app.route("/users",methods=["GET"])
def users():
return "姓名 电话<br/>测试 12389766788"
if __name__ == '__main__':
app.run(host="0.0.0.0",port=8899,debug=True)
页面访问效果如下 二,创建动态路由 代码如下
from flask import Flask
app = Flask(__name__)
users_list = {"1001":["123","张三",19],
"1002":["234","李四",22],
"1003":["345","王二小",8]}
@app.route("/users",methods=["GET"])
def users():
return users
@app.route("/users/<string:account>",methods=["GET"])
def get_user(account):
if account in users_list:
info = users_list[account]
return "%s您好,年龄为%d" %(info[1],info[2])
else:
return "账户不存在"
if __name__ == '__main__':
app.run(host="0.0.0.0",port=8899,debug=True)
页面访问效果如下
|