如何在不暴露flask中的URI字段的情况下重定向?



我想发送一个用户名和密码到一个名为showInternal的页面的post请求;我目前通过以下方式完成:

username = "johnsmith"
password = "password1234"
return redirect(url_for('showInternal', username=username, password=password))

为重定向和

@app.route('/internal', methods=['GET'])
@login_required
def showInternal():
    return render_template('internal.html')

为目标页。从某种意义上说,它把我带到了/internal?password=password1234&username=johnsmith

但是,我不想在url中显示用户的用户名和密码。我试过用methods=['POST']代替短语methods=['GET'],但后来我得到了一个关于该方法不被允许的错误,并且数据无论如何都留在url中。

我怎么能传递这些数据没有它显示在url?

导入JSON和请求模块:import json, request

使用request模块发送post请求:

requests.post('<full-url>', data=json.dumps({'username': 'johnsmith', 'password': 'password1234'}))

然后编辑你的路由:

@app.route('/internal', methods=['POST'])

相关内容

最新更新