I am trying get hands-on with flask-login extension. I am using virtualenv for flask.
I could able to import LoginManager from flask.ext.login in the python interpreter window, but not in the script. Below the import calls in the script.
from flask.ext.login import LoginManager
I am getting below trace.
Traceback (most recent call last):
File "practice/flask_login.py", line 1, in <module>
from flask.ext.login import LoginManager
File "/Users/sunil/co_operative/flask/lib/python2.7/site-packages/flask/exthook.py", line 81, in load_module
reraise(exc_type, exc_value, tb.tb_next)
File "/Users/sunil/co_operative/practice/flask_login.py", line 1, in <module>
from flask.ext.login import LoginManager
ImportError: cannot import name LoginManager
Cause of problem :
Your file name is causing problem.
Explanation:
As mentioned in official flask document:
http://flask.pocoo.org/docs/0.10/extensiondev/, when user try to import flask extension using expression import flask.ext.something, flask will look for module flask_something.
So, import flask.ext.login look for module flask_login which is conflicting by your file name. And flask is trying to find Definition of LoginManager in your file.
Solution
File rename will solve problem.
You have called your script
flask_login.py
. When you import fromflask.ext.SOMETHING
, behind the scenes it imports fromflask_SOMETHING
. You are hiding the realflask_login.py
. Rename your script and you should be good to go.