【问题标题】:flask: hashes "#" in the routing烧瓶:在路由中散列“#”
【发布时间】: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


【解决方案1】:

#之后的一切都是浏览器在本地处理的,不会发送到服务器,所以不能在路由中使用。省略#

http://localhost:8000/afterlogin/some_id_token

【讨论】:

    猜你喜欢
    • 2017-11-22
    • 1970-01-01
    • 2022-01-23
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-15
    相关资源
    最近更新 更多