【发布时间】:2018-02-10 09:02:03
【问题描述】:
我最近正在使用 google API,并使用简单的烧瓶方法来检索一些 id_token。
这是我的代码,注释中有解释:
@app.route('/afterlogin/id_token')
def afterlogin(id): # get the id
print(id) # print it
return render_template(r'creds_view.html', data=id) # and render the template with 'id' in it (for test purposes)
所以发生的情况是用户登录后,api将id_token重定向到http://localhost:8000/afterlogin/#id_token=some_id_token。
但由于某种原因,它向我显示 404 错误。
我认为这是因为网址中的“#”,我想要id_token。我知道 html 中的“#”表示“href”中的路径链接或路由。
所以我试过了。
@app.route('/afterlogin/<path:id>')
但错误仍然存在。
有什么猜测吗?
【问题讨论】:
-
URL中
#之后的所有内容都不会发送到服务器,不能在路由中使用。 -
@Barmar 将其作为答案提交
-
我已经通过尝试
http://localhost:8000/afterlogin/#hello手动检查过它显示我找不到,而且有趣的是当我尝试http://localhost:8000/afterlogin/hey#hello时它会打印hey -
@jamylak 我不知道 Flask,所以我不知道如何纠正他在做什么。
-
查询参数似乎是显而易见的替代方案
标签: python url flask routing url-routing