I’m designing a flask app that will need to call a custom class to read a database and then initialize and load docker containers based on the information retrieved from the db (flask-SQLAlchemy). This class (object) will also need to be accessed by several different routes for re-configuring/controlling the docker containers
What is the best way to do this?
My initial thoughts were to make a seperate file (extensions.py) and do the initial instantiation of the class in that file. Then the main flask app and the routes would import the extensions.py file. I did this approach for my flask-SQLAlchemy db after watching this video:
https://www.youtube.com/watch?v=WhwU1-DLeVw
I would then pass the flask-SQLAlchemy db to my object after the flask app called the db.init_app(app) call to register the db.
Shane Volpe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.