I am very knew to python web development, so please bear with me.
I am trying setup a very basic log-in using Flask and the below code:
@app.route('/')
def index():
if verifyLoggedIn():
someData = gatherSomeData()
return render_template('main.html', data=someData)
else:
return redirect(url_for('login'))
@app.route('/login/', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
if request.form['usr'] == user and request.form['pwd'] == password:
session['user'] = request.form['usr']
session['passwd'] = request.form['pwd']
return redirect(url_for('index'))
else:
return render_template('out.html',name=request.form['usr'])
else:
return render_template('login.html')
When I access the page by going to 'localhost:5000/', I correctly get forwarded to 'localhost:5000/login/'. After I log-in, however, the page loads 'main.html' but the url bar still shows 'localhost:5000/login/'. The problem with this, is that if I hit refresh button to get the new value of 'someData' I end up back at the log-in screen. I find that this is the case after any post action. Am I missing something very fundamental here?
Thanks to those who responded, but after much more searching, I managed to find that the answer was already on stackoverflow :p (sorry, I really did look around a lot before asking)
Url in browser not updated after call of redirect( url_for('xxx' )) in Flask with jQuery mobile
The problem was actually being caused by jquery mobile and my lack of a data-url attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With