flask 简记

路由

路由默认请求方式为 GET,如需增加其他请求方式,使用 methods 参数:

# 增加了 POST 请求方式
@app.route('/hello', methods=['GET', 'POST'])

带参路由

在路由中通过添加一对尖括号 <> 来包裹参数,同时该参数可以用来传递给@route所修饰的函数,但路由参数和函数参数名需相同:

# 其中添加了int转换器,只允许参数为int类型
@app.route('/hello/<int:name_id>')
def hello_flask(name_id):
    return 'hello %s' % (name_id)
原文地址:https://www.cnblogs.com/huwt/p/10941173.html