def create_app(): from colorama import init init() from config import add_configs app = add_configs(Flask(__name__)) from sqlalchemy_utils.functions import database_exists, create_database if not database_exists(app.config.get('SQLALCHEMY_DATABASE_URI')): create_database(app.config.get('SQLALCHEMY_DATABASE_URI'), encoding='utf8') with app.app_context(): from models import db db.init_app(app) app.db = db from models.oauth2 import oauth2_provider oauth2_provider.init_app(app) # import models Migrate(app, db, directory='bin/migrations/') mgr = Manager(app) mgr.add_command('db', MigrateCommand) return mgr
def create_app(): from config import add_configs # Register configurations application = add_configs(Flask(__name__)) with application.app_context(): # Register database (SQLAlchemy) from models import db db.init_app(application) application.db = db """ @:type SQLAlchemy """ # Register OAuth2 from models.oauth2 import oauth2_provider oauth2_provider.init_app(application) # Register BluePrints from controllers import add_blueprints add_blueprints(application) # Register Api from controllers import add_apis from flask_restful import Api add_apis(Api(application)) return application
from flask import Flask from flask_restful import Api from flask_script import Manager, Shell from flask_migrate import Migrate, MigrateCommand from routes import add_routes # routes added in a separate file from config import add_configs # configs added in a separate file from db import db from flask_jwt_extended import JWTManager app = Flask(__name__) add_configs(app) api = add_routes(Api(app)) manager = Manager(app) db.init_app(app) migrate = Migrate(app, db) jwt = JWTManager(app) def make_shell_context(): return dict(app=app, db=db) manager.add_command("shell", Shell(make_context=make_shell_context)) manager.add_command('db', MigrateCommand) if __name__ == "__main__": manager.run()