Loading

6_限制url请求方法(methods)

Flask限制请求访求

  1. Flask中,route方法,默认只能使用GET的方式请求url, 如果想要设置自己的请求方式,那么应该传递一个methods的关键字参数.
  2. 在@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
posted @ 2019-10-07 18:44  未来已来,你来不来  阅读(540)  评论(0)    收藏  举报