import os from flask import Flask # Please, set a config file on top project dir # find example in ressources/app_config.py try: from app_config import Config, ProdConfig, DevConfig, TestConfig except ImportError: pass def create_app(config_class=None): """ App Factory. can be called with configuration class as argument. """ # Configuration Switcher # try to set configuration depending on environment # if no configuration class was given # if config_class is None: FLASK_ENV = os.environ.get('FLASK_ENV') if not FLASK_ENV: FLASK_ENV = 'testing' if FLASK_ENV == 'production': config_class = ProdConfig elif FLASK_ENV == 'development': config_class = DevConfig elif FLASK_ENV == 'testing': config_class = TestConfig else: config_class = Config # Main flask app # app = Flask(__name__) app.config.from_object(config_class) # Get and activate blueprints # from .main import bp as main_bp app.register_blueprint(main_bp) return app