...
/Project Challenge: Create a Login and Logout Mechanism
Project Challenge: Create a Login and Logout Mechanism
In this lesson, we will be authenticating users using login and maintaining a session until they logout.
Problem statement
In this challenge, you are required to add a login and log out mechanism in the project application.
In this challenge, we have already provided you with the LoginForm
, login.html
template and a simple login
view function that returns the form to the template.
π‘ What are sessions in
Flask
?To differentiate between one request and another, we use sessions in Flask. The session stores the information regarding each transaction in the form of cookies. For example, if we login to a website, and then click on another page, we do not get logged out. The reason is that the session maintains our user information.
π‘ How do we use sessions in
Flask
?In
Flask
, we use the globalsession
object to access the current session. This object is a simple dictionary. We can add or remove keys from it. For example, when a user logs ...