Using Flask, How Does The Logout Button Call The Logout Function?
I am using Python Flask to build a website. I can login, but not log out. The logout button does not respond when I click it. The logout function: @bp.route('/logout') def logout()
Solution 1:
If you assign an onclick handler to the button, you'd need to write the Javascrpt to send an AJAX request, and do something with the response. However that route is performing a redirect, instead of returning JSON, so probably better just direct the user to the /logout
URL. For this, use an anchor tag instead of a button:
<ahref="{{ url_for('logout') }}">Logout</a>
If you want to make this appear as an actual button, then you could still style it as so.
For example, with the bootstrap CSS library you could simply assign the relevant classes to that anchor:
<ahref="{{ url_for('logout') }}"class="btn btn-primary">Logout</a>
Post a Comment for "Using Flask, How Does The Logout Button Call The Logout Function?"