[ACCEPTED]-Can't import LoginManager() in Flask-flask
You probably have a circular import. This 10 is fine, but you need to take into account 9 that you'll be working with modules that 8 haven't yet completed all top-level instructions.
If 7 you have code like:
from flask.ext.login import LoginManager from app.admin import admin_blueprint lm = LoginManager() lm.init_app(app) lm.login_view = 'login'
app.admin will be imported 6 before the
lm = LoginManager() line has executed; any code in
app.admin that 5 then tries to address
app.lm will fail.
Move blueprint 4 imports down your module and
lm will have 3 been created already:
from flask.ext.login import LoginManager lm = LoginManager() lm.init_app(app) lm.login_view = 'login' from app.admin import admin_blueprint
See the Circular Imports note in the 'Larger 2 Applications' documentation section of the 1 Flask manual.
More Related questions