Example #1
0
def create_app(test_config=None):
    ''' Creates a flask application object and performs all the necessary configuration.
    
    The 'test_config' parameter should be a python file containing relevant tests
    '''
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_pyfile('defaultconfig.py')
    if test_config is not None:
        # load the tests configuration
        app.config.from_pyfile(test_config)
    elif test_config is None and app.config['ENV'] == 'production':
        # only during production load configuration from instance folder
        app.config.from_pyfile('config.py', silent=True)

    try:
        os.makedirs('instance')
    except OSError:
        pass
    # import the sqlalchemy object and bind it with the application
    from app import models
    models.db.init_app(app)
    models.init_app(app)

    # import the blueprints
    # and register them
    from app import main
    app.register_blueprint(main.bp)
    from app import auth
    app.register_blueprint(auth.bp)
    auth.login_manager.init_app(app)
    return app
Example #2
0
def create_app():
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
    FlaskDynaconf(app)
    views.init_app(app)
    models.init_app(app)

    return app
Example #3
0
def create_app():
    app = Flask(__name__)
    app.wsgi_app = ProxyFix(app.wsgi_app)
    api.init_app(app)
    config.init_app(app)
    models.init_app(app)

    return app
Example #4
0
def create_app(env):
    app = Flask(__name__)
    app.config.from_object(config_by_name[env])

    routes.init_app(app)
    models.init_app(app)
    auth.init_app(app)

    return app
Example #5
0
def init_app() -> Flask:
    """

    :return:
    """
    from app import api
    from app.api import routes
    from app import models
    app = Flask(__name__)
    models.init_app(app)
    routes.init_app(app)
    api.init_app(app)
    admin.init_app(app)
    return app
Example #6
0
def create_app(env):
    app = CustomFlask(__name__)
    app.config.from_object(config_by_name[env])

    routes.init_app(app)
    models.init_app(app)
    auth.init_app(app)

    # Remove all requests and users on reboot
    with app.app_context():
        models.User.query.delete()
        models.Request.query.delete()
        models.db.session.commit()

    return app
Example #7
0
def create_app():
	app = Flask(__name__)
	##################################
	# config
	DB_URL = "postgres+psycopg2://postgres:[email protected]:5432/irrigation"
	# os.environ.get("DATABASE_URL")[0:8] + '+psycopg2' + os.environ.get("DATABASE_URL")[8::]
	app.config['SQLALCHEMY_DATABASE_URI'] = DB_URL
	app.config['SECRET_KEY'] = 'you-will-never-guess'
	models.init_app(app, "10.11.157.211")
	from app.routes.routes import mod_auth as auth_module

	# Register blueprint(s)
	app.register_blueprint(auth_module)
	# login_manager.login_message_category = 'info'
	####################################
	return app
Example #8
0
def create_app(test_config=None):
    app = Flask(__name__, instance_relative_config=True)

    from app import config
    config.init_app(app)

    from app import models
    models.init_app(app)

    from app import auth
    app.register_blueprint(auth.bp)
    from app import blog
    app.register_blueprint(blog.bp)
    app.add_url_rule('/', endpoint='index')

    return app
Example #9
0
def create_app(Config = None):
    """Flask app factory function."""
    app = Flask(__name__)
    app.wsgi_app = HTTPMethodOverrideMiddleware(app.wsgi_app)
    if not Config:
        Config = DefaultConfig if not app.debug else DebugConfig
    app.config.from_object(Config)
    register_blueprints(app)
    models.init_app(app)
    routes.init_app(app)
    templates.init_app(app)
    mail.init_app(app)

    if not app.testing:
        logger.init_app(app)

    if app.debug:
        debug.init_app(app)

    return app
Example #10
0
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
Example #11
0
def create_app(instance_name):
    app = Flask(APP_NAME, instance_relative_config=True)

    # app.config.from_json(f'{instance_name}.json', silent=True)
    app.config.from_json('local.json', silent=True)
    app.config.from_mapping(environ)

    app.config['FLASK_ENV'] = instance_name

    with app.app_context():
        from app import models
        from app import endpoints
        from app import schemas
        from app import migrations
        from app import database

        models.init_app(app)
        endpoints.init_app(app)
        schemas.init_app(app)
        migrations.init_app(app)
        database.init_app(app)

        return app
Example #12
0
def test_init_app_needed(client_empty):
    get_user(client_empty, {})
    init_app(app)
    assert Settings.query.count() == 1
    assert User.query.count() == 1
Example #13
0
def test_init_app_not_needed(client):
    get_user(client, {})
    init_app(app)
    assert Settings.query.count() == 1
    assert User.query.count() == 1
    assert Blocklist.query.count() == 0
Example #14
0
def db_init():
    """First, run the Database init modules."""
    models.init_app(config[os.getenv('FLASK_CONFIG') or 'default'])
Example #15
0
def db_init():
    """First, run the Database init modules."""
    init_app(app)