Getting The Database Connection From Application Context With Flask-restful
I have an app using Flask-Restful and I don't know how to get the database connection info from the application context. Here is what I have so far: app.py: .... from flask.ext.res
Solution 1:
Well, for my project I use this kind of structure:
application/__init__.py
...
app = Flask(__name__)
...
db = SQLAlchemy(app) #because I use sqlalchemy
...
import application.core
application/core.py
from application.api import resource
...
# api definition
application/api/resource.py
from application import db
...
db.doWhatEverYouWant()
...
It's certainly not perfect but I don't have such kind of circular import problems.
Post a Comment for "Getting The Database Connection From Application Context With Flask-restful"