3、URL 传递变量

代码

#encoding:utf-8
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return '这是url传参演示!'

# 默认是字符串类型
@app.route('/user/<name>')
def list_name(name):
    return "接收到的名字为: %s" % name

# 设置成只能传递 整型。还可以设置 float,即浮点型 
@app.route('/news/<int:id>')
def list_news(id):
    return "接收到的id为: %s" % id

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

参考资料

https://weread.qq.com/web/reader/0a932660718ac6bc0a9702e

posted @ 2022-05-29 13:00  tiansz  阅读(182)  评论(0)    收藏  举报