蓝图的所有 post 方法出现 400 http 错误

400 http error on all post method of a blueprint

所以我有这个项目,我已经为它添加了蓝图... 一切正常,我测试了端点。一切都好一切都好。

现在 2 周后,我正在调试和测试我在 sprint 中完成的任务,现在我的所有请求都收到 400 HTTP 错误....

知道是什么导致了这个问题吗?

应用文件

from my_bp import bp
app.register_blueprint(bp,url_prefix="/test")

my_bp 文件

bp = Blueprint("my_bp",__name__)

@bp.route("/test",methods=["GET","POST"]
def test():
return {"test":"helloworld"}

现在,如果我通过 postman 发送一个 get 请求,一切都很好,但是当我尝试发送一个没有正文(或有正文)的简单 post 请求时,我得到了 400错误响应...

提前致谢

P.S。所有其他蓝图都很好,但这个蓝图在我的所有 post 请求中返回 400 P.S。我使用 Post-man 发送请求

原来是和Flask-WTF CSRF保护有关.....

对于任何不知道为什么他们无法获得路线的人运行,这里是答案。

app.init.py:

...
from flask_wtf.csrf import CSRFProtect
...
...
csrf = CSRFProtect()
...

并且在初始化您的 csrf 保护之后,您需要免除路由:

from app import csrf
bp = Blueprint("my_bp",__name__)

@csrf.exempt
@bp.route("/test",methods=["GET","POST"]
def test():
return {"test":"helloworld"}