Flask:如何通过所有GET参数进行重定向? [英] Flask: How to pass all GET parameters to redirect?

查看:61
本文介绍了Flask:如何通过所有GET参数进行重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的事情:

return redirect(app.config['FB_APP_URL'], request.args)

但我有一个例外:

AttributeError: 'ImmutableMultiDict' object has no attribute 'split'

是否有更简单的方法来实现此目的,还是必须遍历request.args?谢谢

Is there an easier way to achieve this or do I have to loop through request.args ? thanks

更新:

使用Paolo的解决方案,这是对我有用的解决方案.

Going with Paolo 's solution, this is the solution that worked for me.

params = urlparse(request.url).query
        return redirect(app.config['FB_APP_URL']+"?"+params) 

推荐答案

您的代码错误,导致第二个参数 redirect 是httpcode(301、302,ecc).

Your code is wrong cause the second parameter to redirect is the httpcode (301, 302, ecc).

您可以使用 url_for 创建完整的url,例如:

You can use url_for to create the full url, something like:

full_url = url_for('.index', **request.args)
return redirect(full_url)

这篇关于Flask:如何通过所有GET参数进行重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆