Python flask blueprint Получить доступ к объекту db

У меня есть главный файл приложения: app/app.py

from flask import Flask, request
from my_blueprint.my_blueprint import my_blueprint
import secrets
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand

app = Flask(__name__)

manager = Manager(app)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)

app.config['SECRET_KEY'] = secrets.token_urlsafe(32)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://god:[email protected]/database_name'

app.register_blueprint(my_blueprint, url_prefix='/')

if __name__ == "__main__":
    manager.run()

У меня есть blueprint:

app/my_blueprint/my_blueprint.py

from flask import Blueprint, request, render_template

my_blueprint = Blueprint("my_blueprint", __name__, template_folder='templates', static_folder='static')

@my_blueprint.route('/')
def index():
    return render_template('my_blueprint/index.html')

Вопрос: Как мне получить доступ к объекту db из my_blueprint.py, который находится в app.py, чтобы внутри blueprint'a работать с базой данных?

Пытался так: from ..app import db, но получил ошибку:

ValueError: attempted relative import beyond top-level package

Ответы (0 шт):