如何根据另一个应用程序的帖子重定向flask网页?

2024-04-25 13:01:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图根据另一个运行python应用程序的帖子重定向网页。是什么限制重定向线路在服务器上运行?print语句成功写入控制台。另外,值得注意的是,当POST请求通过时,我不一定会在这个网页上,但是我想强制服务器呈现那个页面。我也尝试过使用render\u模板,但没有成功。你知道吗

在我的主要应用程序中:

@blueprint.route('/my_route', methods=['GET','POST')
#@login_required # I had to uncomment this in order for it work
def my_route():
    if request.method == 'POST':
        data = request.args.get('my_data')
        print(data)

    return redirect(url_for('mypath_blueprint.my_route'))

从我的其他申请(或邮递员,如果你喜欢)

import requests
r = requests.post('http://my_ip_address:5000/mypath/my_route', data={'my_data':1}, allow_redirects=True)

Tags: 服务器应用程序网页fordatarequestmypost
1条回答
网友
1楼 · 发布于 2024-04-25 13:01:16

而不是打印数据重定向用户的数据

@blueprint.route('/my_route', methods=['GET','POST')
#@login_required # I had to uncomment this in order for it work
def my_route():
    if request.method == 'POST':
        data = request.args.get('my_data')
        return redirect(url_for('mypath_blueprint.my_route', data=data))

    return render_template("mypath_blueprint.my_route")

要查看您是否被重定向,请打印出状态代码

print(r.history)

如果302表示URL重定向

相关问题 更多 >