How can I import app from __init__.py and why I'm getting this error?
In bytewar.user.views
you import db from your __init__.py
. That however is only defined a few lines below the import. So at the time the import is done, db does not exist yet, which the error confirms. When you look at the example code for application factory 1 you see that the app
variable is only used after it is defined, your code should do that too. Move your imports to the bottom and you are set.
As an aside: Why do you create your app
in the factory and immediately overwrite it? Leave the second creation out.