Home > database >  Flask redirect without url params
Flask redirect without url params

Time:07-30

I have 2 flask app, client and server respectively And I wanna download some files from server by redirecting user directly to the server So basically I want redirect to this route:

@app.route('/api/1.0/conf/<token>', methods=['GET'])
def returnPeerConf(token):
    if token is valid:
        return file

So I'm write client like this:

@app.route("/downloadConf/<token>", methods=["GET"])
def downloadConf(token):
    url = f"http://{ipAddress}/api/1.0/conf/{token}"
    redir = redirect(url)
    return redir

I wanna get url like: http://ipAddress/api/1.0/conf/myGreatToken But get: http://ipAddress/api/1.0/conf/{'token': 'myGreatToken'}

And this doesn't work. How to redirect without params?

CodePudding user response:

Try using urllib.parse module quote() function. https://docs.python.org/3.6/library/urllib.parse.html#urllib.parse.quote

CodePudding user response:

It seems like token is a dict value. Perhaps you could try getting the value for token['token'] and then add it to the url, instead of putting the entire token dict in.

For example:


app.route("/downloadConf/<token>", methods=["GET"])
def downloadConf(token):
    token_val = token['token']
    url = f"http://{ipAddress}/api/1.0/conf/{token_val}"
    redir = redirect(url)
    return redir

  • Related