0

my problem at the moment is that my redirect won't reload the page.

I send a post request to my web server to get my informations. On the server site like "/wait" i wait until i get a post request. The post request will be catched in another route like "/request". And here it should be reloaded with a redirect to the "/wait" url but don't work and i don't know why.

@app.route("/request", methods=["POST"])
def request():
    received_data = request.data.decode()
    data = load_csv(received_data)
    return redirect(url_for("request"))

@app.route("/wait")
def wait():
    if data :
        return redirect("https://google.com")
    else:
        return render_template('wait.html')

I don't know why the redirect from the request won' t work.

davidism
  • 121,510
  • 29
  • 395
  • 339
XaniXxable
  • 109
  • 1
  • 9
  • Your `def wait()` function would most definitely not work. There is no reference to the `data` variable, and therefore no way for Python to know what `data` is. Check this out [here](https://stackoverflow.com/questions/10434599/how-to-get-data-received-in-flask-request). – felipe Jul 29 '19 at 20:34

1 Answers1

0

You have only defined 'data' in the local scope of the function request(). If I were you, I would probably use the Flask session variable to store the data. Session is a dictionary that is unique to each session on your website, so it will be different for each person if they are using your website concurrently.

One way to do this might be:

received_data = request.data.decode()
request['data'] = load_csv(received_data)

And then in your wait() function,

if session.get('data'):
    return redirect("https://google.com")
else:
    return render_template('wait.html')