你遇到的 “Method Not Allowed” 错误通常是因为你尝试使用不允许的 HTTP 方法访问某个 URL。在你的代码中,你限定了 /get_user
路由只接受 POST
请求:
@app.route('/get_user', methods=['POST'])
要访问这个路由,你需要使用 POST
请求。如果你是通过浏览器访问,浏览器通常在地址栏中输入 URL 时默认使用 GET
请求。
你可以使用类似 curl
命令行工具或者 Postman 这样的工具,发送一个 POST
请求来测试这个路由。例如,使用 curl
:
curl -X POST http://localhost:5000/get_user
或者使用 Postman:
- 设置 URL 为
http://localhost:5000/get_user
。 - 选择
POST
方法。 - 发送请求。
这样,你应该能够解决 “Method Not Allowed” 错误,因为你明确地允许了这个路由仅接受 POST
请求。