Exemple #1
0
def create_app(config_name=None):
    if config_name is None:
        config_name = os.getenv('FLASK_CONFIG', 'development')

    app = Flask(__name__)

    # 加载配置变量
    app.config.from_object(config[config_name])

    # 注册日志处理器
    register_logging(app)

    # 初始化插件
    register_extensions(app)

    # 注册蓝本(blueprint)
    register_blueprints(app)

    # 注册项目自定义命令
    register_commands(app)

    # 注册shell上下文处理函数
    register_shell_context(app)

    return app
def create_app(test_config=None):
    """Create and configure an instance of the Flask application."""
    if test_config is None:
        dictConfig(Config.LOGGING_DICT_CONFIG)
    app = Flask(__name__)

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_object(Config)
    else:
        # load the test config if passed in
        app.config.from_object(test_config)

    register_extensions(app)
    register_routes(app)
    register_commands(app)

    with app.app_context():
        from sqlalchemy.orm import configure_mappers
        configure_mappers()

        from app.api.services.ogc_data_service import OGCDataService
        OGCDataService.refreshAllData()

    return app
Exemple #3
0
def create_app(config_object=None):
    """Create and configure an instance of the Flask application."""
    app = Flask(__name__)

    config = config_object if config_object else Config
    app.config.from_object(config)

    register_extensions(app)
    register_routes(app)
    register_commands(app)

    return app
Exemple #4
0
def create_app(config_name=None):
    if config_name is None:
        config_name = os.getenv('FLASK_CONFIG', 'development')

    app = Flask(__name__)
    app.config.from_object(config[config_name])

    register_blueprints(app)
    register_extensions(app)
    register_commands(app)
    register_global_errors(app)

    return app
Exemple #5
0
def create_app(config=config['default']):
    app = Flask(__name__)

    app.config.from_object(config)
    config.init_app(app)

    register_extensions(app)
    register_commands(app)

    @app.route('/')
    def index():
        return '<a href="/admin/">Click me to go to Admin!</a>'

    return app
Exemple #6
0
def create_app(config_object=config.Config):
    app = Flask(__name__)
    app.config.from_object(config_object)
    app.jinja_env.lstrip_blocks = True
    app.jinja_env.trim_blocks = True

    register_logger(app)
    register_extensions(app)
    register_blueprints(app)
    register_commands(app)
    register_admin(app)
    register_error_handlers(app)

    return app
Exemple #7
0
def create_app(test_config=None):
    """Create and configure an instance of the Flask application."""
    app = Flask(__name__)

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_object(Config)
    else:
        # load the test config if passed in
        app.config.from_object(test_config)

    register_extensions(app)
    register_routes(app)
    register_commands(app)
    return app
def create_app(config_name=None):
    if config_name is None:
        config_name = os.getenv('FLASK_CONFIG', 'development')

    app = Flask(__name__)

    config_obj = config[config_name]
    app.config.from_object(config_obj)
    config_obj.init_app(app)

    register_extensions(app)
    register_views(app)
    register_commands(app)
    config_oauth(app)

    return app
def create_app(config_object=None):
    """Create and configure an instance of the Flask application."""
    app = Flask(__name__)

    config = config_object if config_object else Config
    app.config.from_object(config)

    register_extensions(app)
    register_routes(app)
    register_commands(app)

    @api.errorhandler(Exception)
    def default_error_handler(error):
        app.logger.error(str(error))
        app.logger.error('REQUEST\n' + str(request))
        app.logger.error('HEADERS\n ' + str(request.headers))
        return {
            'status': getattr(error, 'code', 500),
            'message': str(error),
        }, getattr(error, 'code', 500)

    return app
Exemple #10
0
def init_commands(app):
    from app.commands import register_commands
    register_commands(app)
migrate = Migrate()
mail = Mail()

# basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
CORS(app)  ## enable CORS on all routes
app.config.from_object(app_config[env_name])

app.logger.info(f"\n \
######################################################### \n \
#   ENV:        {env_name}                                \n \
#   DB_HOST:    {app.config['DB_HOST']}                   \n \
#   ENV:        {env_name}                                \n \
######################################################### ")

# Set up extensions
from app.models import db, ma
db.init_app(app)
ma.init_app(app)
migrate.init_app(app, db)
mail.init_app(app)

# Set up logging
setup_logger(app)

from app.views import register_blueprint_view
register_blueprint_view(app)

from app.commands import register_commands
register_commands(app)