def create_app(overwrite_db=None): """ Flask app factory method. :param overwrite_db: URI for local SQLITE DB, used for tests. :return: """ app = Flask(__name__) from app import extensions from app import modules from app.config_flask import config_flask from app.helpers.requestid import requestid from app.extensions.sqlalchemy.create_db import create_db config_flask(app) if overwrite_db: app.config['SQLALCHEMY_DATABASE_URI'] = overwrite_db extensions.init_app(app) modules.init_app(app) if overwrite_db: create_db(app) # Error handling method # pylint: disable=unused-variable @requestid @app.errorhandler(500) def internal_error(exception): app.logger.error(exception) return make_response(jsonify(exception), 500) return app
def create_app(env_config: str) -> Flask: """Builds an application based on environment configuration. Parameters ---------- env_config Environment configuration. Returns ------- Flask A `flask.flask` instance. Notes ----- Environment configuration values could be:: config.ProdConfig config.DevConfig config.TestConfig """ app = flask.Flask(__name__) app.config.from_object(env_config) app.wsgi_app = Middleware(app) _init_logging(app) extensions.init_app(app) _register_blueprints(app) exceptions.init_app(app) return app
def create_app(): app = Flask(__name__) extensions.init_app(app) modules.init_app(app) CORS(app, supports_credentials=True) return app
def create_app(): # Setup connexion connexion_app = connexion.FlaskApp(__name__) connexion_app.add_api('api.yaml') flask_app = connexion_app.app # Flask setup extensions.init_app(flask_app) # Database setup extensions.create_db(flask_app) return flask_app
def create_app(import_name, *args, **kwargs): kwargs.setdefault('config', config) app = create_api_app(import_name, *args, **kwargs) from app import logging logging.init_app(app) from app import extensions extensions.init_app(app) from app import modules modules.init_app(app) from app import commands commands.init_app(app) return app
def create_app(): app = Flask(__name__) config_opts = { 'development': 'ConfigDev', 'staging': 'ConfigStage', 'production': 'ConfigProd' } config_path = 'config' config_env = config_opts[app.config.get('ENV')] app.config.from_object(f'{config_path}.{config_env}') extensions.init_app(app) blueprints.init_app(app) @app.route('/') @app.route('/<name>') def index(name='World'): return f'Hello {name}' return app
def create_app(config_name='default'): """ 初始化,创建app """ from app import services from app import routes from app import models # 建立静态文件static,templates的路径 static_dir = os.path.join(BASE_DIR, 'static') templates_dir = os.path.join(BASE_DIR, 'templates') # 创建app实例对象 app = Flask(__name__, template_folder=templates_dir, static_folder=static_dir) # 加载配置 # app.config.from_object(config.get(config_name) or 'default') app.config.from_object(config.get(config_name)) # 执行额外的初始化 config.get(config_name).init_app(app) # 设置debug=True,让toolbar生效 # app.debug=True # 加载扩展 extensions.init_app(app) # 配置蓝本 routes.init_app(app) # 配置全局错误处理 config_errorhandler(app) models.init_app(app) services.init_app(app) # 返回app实例对象 return app
def create_app(): app = Flask(__name__) extensions.init_app(app) routes.init_app(app) return app
def _init_extensions(app: Flask) -> None: extensions.init_app(app)