Redirect From One Page To Another Along With Some Post Data In Flask
I am working on a Flask project. After successful execution of login function, it should redirect on home page with some data. The data should be send by post. How can this be done
Solution 1:
For send data after successful login you can use url_for
within of redirect
something as this:
@app.route('/login', methods = ['POST'])
def login():
if request.method == 'POST' and request.form.get("username") == 'admin':
return redirect(url_for('success',data=request.form.get("data")),code=307)
else:
return redirect(url_for('index'))
After success login you can use your data to send with data=data
, so in your other view you get that data.
@app.route("/test/argument", methods=['POST'])
def success():
messages = request.form.get('data') # counterpart for url_for()return messages
Post a Comment for "Redirect From One Page To Another Along With Some Post Data In Flask"