如何在不显示烧瓶中的URI字段的情况下重定向?

时间:2016-08-18 01:13:46

标签: python redirect post flask

我想发一个帖子请求向名为showInternal的页面发送用户名和密码;我目前通过以下方式实现这一目标:

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

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

如果不将这些数据显示在网址中,我该如何传递这些数据?

1 个答案:

答案 0 :(得分:0)

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

使用请求模块发送帖子请求:

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

然后编辑你的路线:

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