【问题标题】:Flask restful is doing GET instead of POSTFlask restful 正在做 GET 而不是 POST
【发布时间】:2021-06-11 22:19:07
【问题描述】:

我有一个用 python 构建的简单的 flask 和 flask_restful 应用程序,如图所示:

from flask import Flask
from flask_restful import Api, Resource

app = Flask(__name__)
api = Api(app)


class Route(Resource):
    def post(self):
        return "Posted"


api.add_resource(Route, '/')

if __name__ == '__main__':
    app.run(debug=True)

但是,当我运行此应用并导航到链接时,我收到以下消息:

{
    "message": "The method is not allowed for the requested URL."
}

我的烧瓶输出如下所示:

 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 691-936-340
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [11/Jun/2021 10:07:33] "GET / HTTP/1.1" 405 -

我的 API 似乎在应该发帖时进行了 get 调用。有什么建议吗?

【问题讨论】:

    标签: python flask flask-restful


    【解决方案1】:

    当您通过浏览器导航时,它会发送 GET 请求,这就是您收到
    {"message": "The method is not allowed for the requested URL." }
    的原因 我尝试通过邮递员发送POST 请求,它返回了有效响应。

    【讨论】:

    • 谢谢。当我在命令行中使用 curl 访问我的 URL 时,它确实返回了我想要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    • 2018-10-16
    • 1970-01-01
    • 2016-01-27
    • 1970-01-01
    • 2018-09-04
    • 2021-09-26
    相关资源
    最近更新 更多