如何使用flask.redirect发送POST请求?

Muk*_*kar 3 python post redirect flask

我正在尝试创建一个 Flask 服务,在其中我想将来自一个 request.form 的数据以 json 格式发送到另一个 url,请问任何人都可以帮助我实现这一目标吗?

redirect(url_for('any_method'), json = json.dumps(my_form_dict))
Run Code Online (Sandbox Code Playgroud)

当我尝试执行上面的代码时,出现以下错误:

TypeError: redirect() got an unexpected keyword argument 'json' The above is the error here.
Run Code Online (Sandbox Code Playgroud)

小智 8

您可以使用 307 状态代码重定向 POST 请求。使用:

redirect(url_for('any_method', json=json.dumps(my_form_dict)), code=307)
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅此答案: 在 Flask 中重定向时发出 POST 请求