July 2019
Beginner to intermediate
302 pages
9h 38m
English
Sometimes, you may want a single SQLAlchemy db instance to be used across multiple applications, or create an application dynamically. In such cases, we might not prefer to bind our db instance to a single application. Here, we will have to work with the application context to achieve the desired outcome.
In this case, we will register our application with SQLAlchemy differently as follows:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
def create_app():
app = Flask(__name__)
db.init_app(app)
return app
Now, all the operations that were ...