AttributeError: 'Flask' object has no attribute 'login_manager' -- Login_Manager

I'm just learning Flask, and I encountered this problem too. I found that I had not initialized the login_manager to the app.

So I changed:

login_manager = LoginManager()

to

login_manager = LoginManager(app)

and that solved my issue.


You run your app before initializing the LoginManager. So you should have:

app.secret_key = 'xxxxyyyyyzzzzz'

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'

app.run(debug = DEBUG, host=HOST, port= PORT)

Tags:

Python

Flask