Ok. I think I figured this one out by myself too. I am using this snippet now. If you have any better ideas, please let me know
Base = declarative_base()
engine = None
sessionmaker = sessionmaker()
db = scoped_session(sessionmaker)
def configure_engine(url):
global sessionmaker, engine, db
engine = create_engine(url)
db.remove()
sessionmaker.configure(bind=engine)
def create_app(name=__name__, configuration=None):
from .modules import admin
from .modules.admin.models import User
app = Flask(name, static_path='/static', template_folder=template_dir)
load_config(app, configuration)
celery.config_from_object(app.config)
configure_engine(app.config['SQLALCHEMY_DATABASE_URI'])
filters.init_app(app)
register_local_modules(app)
admin.init_app(app)
login_manager.init_app(app)
@login_manager.user_loader
def load_user(id):
return db.query(User).get(id)
# Enable the DebugToolbar
if app.config['DEBUG_TOOLBAR']:
toolbar = DebugToolbarExtension(app)
return app