Skip to Content
Learn
Introduction to Authentication with Flask
Logout

You’ve successfully authenticated, Nice. Now only logged in users can see our zesty recipe! But now that you’re done you don’t want to remain logged in. Let’s enable the logout feature to protect the recipe.

Flask-login provides us with a logout_user method to facilitate this.

@app.route("/logout") @login_required def logout(): logout_user() return redirect(url_for('index'))

Awesome! We have our logout working on our back end. Lets implement a logout link in our html to trigger the logout code to run.

in logged_in.html update the code with the logout link

<!DOCTYPE> <head> </head> <body> <a class="blue pull-left" href="{{ url_for('logout') }}">Logout</a> </body>

Congrats on learning authentication with Flask!

Instructions

1.

import logout_user from flask-login

2.

Write the html code for our logout.

Folder Icon

Sign up to start coding

Already have an account?