I have the following file structure for a Flask application:
myapplication/
run.py
myapplication/
__init__.py
views/
__init__.py
models.py
...
templates/
static/
And I have initialised the database in myapplication/__init__.py
using SQLAlchemy. I want to import the database object in models.py
though I'm unsure on how to do it.
I read this answer and tried to import the database object from myapplication/__init__.py
using relative imports like this:
from ... import db
but I receive this error: ValueError: Attempted relative import in non-package
.
So how to I get to the database object in myapplication/__init__.py
for models.py
? Thanks.