-
Although I was able to solve my Now that I have to work inside an application context to reflect my database tables, I can't import my models into any of my blueprints without getting models.py
/blueprint/init.py
init.py
In short:
I've been banging my head against the wall days now. I feel like I must be missing something glaringly obvious. Any help would be much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need an active context when the code that needs it is evaluated. Module code is evaluated when it is imported. Therefore, you need a context active when you import the models, which happens as a side effect when you import the blueprints. def create_app():
...
with app.app_context():
from .blueprint import bp
app.register_blueprint(bp)
...
return app |
Beta Was this translation helpful? Give feedback.
You need an active context when the code that needs it is evaluated. Module code is evaluated when it is imported. Therefore, you need a context active when you import the models, which happens as a side effect when you import the blueprints.