路由默认允许哪些方法?不允许的方法得到什么响应?Allow 头里是什么?这篇用 4 种路由和 7 种方法做一张完整的矩阵。
/default methods = ['GET', 'HEAD', 'OPTIONS'] /post-only methods = ['OPTIONS', 'POST'] /multi methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST'] /g methods = ['GET', 'HEAD', 'OPTIONS'] /p methods = ['OPTIONS', 'POST'] /d methods = ['DELETE', 'OPTIONS'] /mv methods = ['GET', 'HEAD', 'OPTIONS', 'POST']
上一篇:静态文件路由的注册方式;下一篇:OPTIONS 与 HEAD 自动处理。
路径 GET POST PUT DELETE PATCH HEAD OPTIONS /default 200 405 405 405 405 200 200 /post-only 405 200 405 405 405 405 200 /multi 200 200 405 200 405 200 200 /mv 200 200 405 405 405 200 200 PUT /default 的 405 响应: 405 METHOD NOT ALLOWED | Allow = OPTIONS, HEAD, GET 正文: <!doctype html> | <html lang=en> | <title>405 Method Not Allowed</title> | <h1>Method Not Allowed</h1> | <p>The method is not allowed for the requeste
GET /multi → multi GET | POST /multi → multi POST | DELETE /multi → multi DELETE 方法写成小写 "get" 的请求 → 200 multi GET
methods=["get","post"] 之后规则的 methods: ['GET', 'HEAD', 'OPTIONS', 'POST'] methods="POST" → TypeError: Allowed methods must be a list of strings, for example: @app.route(..., methods=["POST"]) methods=["FOO"] 与自定义方法 FOO 请求 → 200
MethodView 的 methods 属性: ['GET', 'POST'] PUT /mv → 405 | Allow = OPTIONS, HEAD, GET, POST
POST + X-HTTP-Method-Override: DELETE → 200 收到 DELETE