带URL和API密钥的烧瓶重定向

时间:2020-04-10 08:50:20

标签: python redirect flask

我有两个端点,我想从一个端点重定向到另一个端点。两者都需要相同的api密钥:

@blueprint.route("v1/method/<param>", methods=["PUT"])
@api_key_required
@write_required(api=True)
def method(param):
    return redirect(url_for('v2.method', param=param), code=307)
@blueprint.route("v2/method/<param>", methods=["PUT"])
@api_key_required
@write_required(api=True)
def method(param):
    #handle the request

重定向似乎可以正常工作,但似乎未传递api_key。我收到unauthorised状态。我该怎么办?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。 request.args需要作为附加参数传递。所以正确的代码是:

return redirect(url_for('v2.method', param=param, **request.args), code=307)