techwithtim / Flask-Web-App-Tutorial

Code for the note storing flask web app made during a YouTube video.
922 stars 1.02k forks source link

'Flask' object has no attribute 'login_manager' #80

Open Metior21 opened 1 year ago

Metior21 commented 1 year ago

Traceback (most recent call last): File "c:\Users\x\Desktop\Flask-Web-App-Tutorial-main\main.py", line 3, in app = create_app() File "c:\Users\x\Desktop\Flask-Web-App-Tutorial-main\website__init__.py", line 15, in create_app from .views import views File "c:\Users\x\Desktop\Flask-Web-App-Tutorial-main\website\views.py", line 2, in from flask_login import login_required, current_user File "C:\Users\x\AppData\Local\Programs\Python\Python310\lib\site-packages\flask_login__init__.py", line 12, in from .login_manager import LoginManager File "C:\Users\x\AppData\Local\Programs\Python\Python310\lib\site-packages\flask_login\login_manager.py", line 33, in from .utils import _create_identifier File "C:\Users\x\AppData\Local\Programs\Python\Python310\lib\site-packages\flask_login\utils.py", line 23, in login_manager.init_app(app) NameError: name 'login_manager' is not defined

I've tried following solution but it still gave the same error.

https://stackoverflow.com/questions/31067249/attributeerror-flask-object-has-no-attribute-login-manager-login-manager

ugrcnkaya commented 1 year ago

same here? any solution?

purvaa27 commented 1 year ago

ANY SOLUTIONS??/

sylvan2501 commented 1 year ago

I think that under db.init_app(app) in the init.py file The following lines need to be added: login_manager = LoginManager() login_manager.login_view = 'auth.login' login_manager.init_app(app) as well as a decorator function (I am not sure about it) please refer to https://www.digitalocean.com/community/tutorials/how-to-add-authentication-to-your-app-with-flask-login