...

/

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 global session 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 ...