6_限制url请求方法(methods)
Flask限制请求访求
- 在
Flask中,route方法,默认只能使用GET的方式请求url, 如果想要设置自己的请求方式,那么应该传递一个methods的关键字参数. - 在@app.route()中, 指定 methods参数, 如:
@app.route('/', methods=['POST', 'GET'])# 里面的请求方法可以是小写的,也可以是大写的
@app.route('/', methods=['post', 'get'])
def index():
return 'index'
@app.route('/user/<int:user_id>/', methods=['POST', 'GET'])
def user_detail(user_id):
print(user_id)
return '用户id为:%s' % user_id

浙公网安备 33010602011771号