ImportError: cannot import name 'app'

See original GitHub issue
 Hello,miguel。I have finished your awesome "dog book" three weeks ago, and my code  bases on your  code. The 'app' is created in app/__init__.py, 
 Now I want  to add the full-text search function,but i don't know how to import 'app'.When i tried  to import it directly  like"from app import app", it didn't work and "ImportError: cannot import name 'app'" came out. i have try google and stackoverflow , but there were not helpful answer.
so i ask you for help. My english is not very well, hope you can understand what i say.Have a nice day!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
miguelgrinbergcommented, Oct 21, 2016

Your problem is that you have circular dependencies. Some of the imports in manage.py that appear before the app = create_app() line issue a from manage import app, and that obviously fails.

Move the from app import create_app and app = create_app lines above your other imports, maybe that’ll help.

2reactions
miguelgrinbergcommented, Oct 20, 2016

Are you using a factory function, like in the book? If you are, then app does not exist as a symbol, you only have create_app, the function that creates it.

So you need to import app from the module that creates it. For example, if you call create_app in manage.py, then you can import it from there with from manage import app.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flask ImportError: cannot import name app - Stack Overflow
I keep getting a ImportError: cannot import name app error on the first line of run.py . All the other questions seem to...
Read more >
ImportError: cannot import name 'app' from 'app' (unknown ...
I encountered this error. It looks like my problem was was in naming the file init.py instead of init.py (with 2 underscores on...
Read more >
cannot import name 'app' from 'site' : Forums - PythonAnywhere
hi there. it's my first time deploying a Flask app. ... Error running WSGI application ImportError: cannot import name 'app' from 'site' ...
Read more >
Flask App shows ImportError: cannot import name 'Markup ...
Flask App shows ImportError: cannot import name 'Markup' from 'jinja2' | After deploying. Hello,. I have successfully deployed a flask web ...
Read more >
cannot import name 'app' from partially initialized module 'app ...
The reason you're getting an error is because agreements.py can't import functions from approvals.py while approvals.py is simultaneously trying to import ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found