Adding a Flask class instance into a LoginManager Class instance Adding a Flask class instance into a LoginManager Class instance flask flask

Adding a Flask class instance into a LoginManager Class instance


I found the answer myself.

in the login_manager = LoginManager(app) we have created an instance of the class LoginManager and passed the app class, which is an instance of Flask. The reason behind this is, we can use the methods of the app instance from within the login_manger instance now. Hence we can extend functionalities of the app.

Best was to understand this was to reproduce this in small exercise files.

Here my example:

File 1 (This will serve as example for Flask Module):

class FirstClass:def _init_(self):    passdef say_1(self):    print("Hello First Class")def _repr_(self):    print("hello from first class")

File 2 (This will serve for example of LoginManager Module):

class SecondClass:def _init_(self, x):    self.x = x    passdef say_2(self):    print("Hello Second Class")

File 3 (from which we run the app):

from first import FirstClassfrom second import SecondClassone = FirstClass()two = SecondClass(one)