flask:在路由中散列“#”

P.h*_*ter 0 python url routes url-routing flask

我最近正在使用 google API,并使用简单的 Flask 方法来检索一些 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)
Run Code Online (Sandbox Code Playgroud)

那么发生的情况是,用户登录后,API 将重定向id_tokenhttp://localhost:8000/afterlogin/#id_token=some_id_token.

但由于某种原因,它向我显示 404 错误。我认为这是因为网址中的“#”,我想要id_token. 我知道html中的“#”意味着“href”中的路径链接或路由。

所以我尝试过。

@app.route('/afterlogin/<path:id>')
Run Code Online (Sandbox Code Playgroud)

但错误仍然存​​在。

有什么猜测吗?

Bar*_*mar 5

之后的所有内容#都由浏览器在本地处理,不会发送到服务器,因此您不能在路由中使用它。省略#

http://localhost:8000/afterlogin/some_id_token
Run Code Online (Sandbox Code Playgroud)