I have a very simple python program using Flask as shown below. It processes the login with a popup and logout. The problem is that the URL in the browser is not updated by calling redirect (url_for ()).
@app.route('/') def index(): if not 'username' in session: # contains a button showing a login popup form with action set to '/login' return render_template('welcome.html') else: # contains a logout button with a href to '/logout' return render_template('webapp.html') @app.route('/login', methods=['POST']) def login(): session['username'] = request.form['username'] return redirect(url_for('index')) @app.route('/logout') def logout(): session.pop('username', None) return redirect(url_for('index'))
When accessing "/", a welcome page is displayed. When I click on the button, a login popup is displayed and its form action is redirected to '/ login'. This works and the login () function is called and executed. It also redirects, but the browser does not update the display URL.
Thus, the webapp page is displayed with the URL / logon. When I click reload, I get an error message because it tries to reboot / log in while it needs to reload '/', where it was redirected.
The same thing happens with / logout. When the webapp page is displayed, and I press the exit button, the / logout page is loaded, which executes the logout () function and redirects to the index. But the url is left to log out.
If I then reload the page, it will succeed because / logout accepts the GET method, and then the URL is updated to / as it should have been in the first place.
I get the impression that this is a problem with jQuery for mobile, but cannot find the problem. From the point of view of python and Flask, it matches all the login examples I could find.
python jquery-mobile flask flask-login
chmike
source share