flask icon indicating copy to clipboard operation
flask copied to clipboard

AttributeError: 'module' object has no attribute 'app'

Open leninworld opened this issue 9 years ago • 6 comments

I pulled the latest master branch and ran "python setup.py install". Then, I tried to load flask.app.test_client(), but it fails. Please let me know how to overcome this. Thank you!

MOOLE04mac1231:flask moole04$ python
Python 2.7.10 (default, Feb  7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import flaskr
>>> t= flaskr.app.test_client()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'app'
>>>

leninworld avatar Oct 04 '17 15:10 leninworld

Because you have to create an app in your own project. flask.app is a module in Flask that has the Flask object you use to do that.

davidism avatar Oct 04 '17 15:10 davidism

I think he's trying to do something with flaskr

ThiefMaster avatar Oct 04 '17 15:10 ThiefMaster

I followed what is shown in link http://flask.pocoo.org/docs/0.12/testing/. Pls see the line "self.app = flaskr.app.test_client()". So it is expected to work. Please let me know if I am wrong.

leninworld avatar Oct 04 '17 15:10 leninworld

In your interpreter you need to use from flaskr import flaskr, like the test file does.

davidism avatar Oct 04 '17 16:10 davidism

This is what I get when I try.

from flaskr import flaskr Traceback (most recent call last): File "", line 1, in ImportError: cannot import name flaskr

leninworld avatar Oct 04 '17 16:10 leninworld

You didn't install flaskr in editable mode then.

cd examples/flaskr
pip install -e .

davidism avatar Oct 04 '17 16:10 davidism