Search code examples
pythonurlflaskroutesurl-routing

flask: hashes "#" in the routing


I'm working with google API lately and use simple flask method to retrieve some id_token.

here is my code with explanations in comment:

@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)

So what happens is that after the user logins, the api redirects the id_token to http://localhost:8000/afterlogin/#id_token=some_id_token.

but for some reason it is showing me 404 error. i think it is because of the '#' in the url , i want the id_token. i know that '#' in html means for path linking or routing in 'href'.

so for that i tried.

@app.route('/afterlogin/<path:id>')

but the error still persists.

any guesses?


Solution

  • Everything after # is processed locally by the browser, it's not sent to the server, so you can't use it in routing. Leave out the #:

    http://localhost:8000/afterlogin/some_id_token