I am building a website using Flask and SQLAlchemy in Python, and having great fun so far.
There is something I'm not sure about, however. The following code is used to connect to the database:
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'bla'
db = SQLAlchemy(app)
How do I reuse this object in different files, though? I have tried storing it in g
, but this causes problems in the database models, when I try to use the database outside a web request's scope. Is there a standard method to make db
accessible in multiple files/classes?