When building a web application we might first start with the base of our application serving an endpoint saying “Hello World”.

from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello Authentication World!'

The application we will be building will show how to use tools in Flask to authenticate users. The primary tool we can use to achieve our purposes of authenticating in Flask is Flask-Login.

Flask-Login is a third-party package that allows us to use pieces of code that enable us to perform authentication actions in our application.

We can manage user logins with the LoginManager object from within Flask-Login, as shown below:

from flask_login import LoginManager login_manager = LoginManager()
  • LoginManager is imported from the flask_login package
  • a new LoginManager object named login_manager is created

Once a LoginManager object is defined, we need to initialize the manager with our application. This can be done with the init_app() method of a LoginManager:

  • our instance of LoginManager, login_manager, calls its init_app() method with app, an initialized Flask app, as an argument



Import LoginManager from flask_login in app.py


Create an instance of LoginManager named app_login_manager.


Initialize your login_manager with the app provided in app.py.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?