コード例 #1
0
ファイル: app.py プロジェクト: Jayden-Liang/mypractice
def extension(app):
    print('hi there')
    csrf.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    moment.init_app(app)
    return None
コード例 #2
0
def create_app():
    app = Flask(__name__)

    config = os.environ.get('APP_SETTINGS', 'project.config.ProductionConfig')
    app.config.from_object(config)

    for bp in all_blueprints:
        import_module(bp.import_name)
        app.register_blueprint(bp)

    login_manager.login_view = "index.register"

    logging.config.dictConfig(app.config["LOG_CONFIG"])

    if app.config.get('TESTING'):
        werkzeug_logger = logging.getLogger('werkzeug')
        werkzeug_logger.setLevel(logging.ERROR)

    csrf.init_app(app)
    toolbar.init_app(app)
    db.init_app(app)
    # FIXME: OMG Flask-SQLAlchemy doesn't set app instance when init_app()
    db.app = app
    login_manager.init_app(app)
    login_manager.user_loader(load_user)
    redis_store.init_app(app)
    oauth.init_app(app)
    cache.init_app(app, config={'CACHE_TYPE': 'redis'})

    return app
コード例 #3
0
def create_app():

    app = Flask(__name__, static_url_path='/static')
    used_config = environ.get('APP_SETTINGS', 'config.ProductionConfig')
    app.config.from_object(used_config)

    with app.app_context():
        for module in app.config.get('DB_MODELS_IMPORT', list()):
            import_module(module)

    for bp in all_blueprints:
        import_module(bp.import_name)
        app.register_blueprint(bp)

    logging.config.dictConfig(app.config["LOG_CONFIG"])
    db.init_app(app)
    mail.init_app(app)
    celery.init_app(app)
    csrf.init_app(app)
    app.template_context_processors[None].append(inject_pagechunks)
    app.jinja_env.filters['strftime'] = datetime

    return app
コード例 #4
0
def configure_extensions(app: Flask):
    """ Configure flask app extensions. """
    from project.extensions import login_manager
    from project.extensions import csrf
    from project.extensions import oauth
    from project.services.account import (
        AccountService,
        AnonymousAccount,
        ANONYMOUS_ACCOUNT,
    )

    login_manager.init_app(app)
    csrf.init_app(app)

    login_manager.user_loader(AccountService.get_by_id)
    login_manager.anonymous_user = AnonymousAccount
    login_manager.login_view = "static.login"

    # remove db and user_settings when needed
    @app.teardown_appcontext
    def teardown_db(_):
        g.pop("user_settings", None)
        g_db = g.pop("db", None)
        if g_db is not None:
            g_db.close()

    oauth.init_app(app)

    if app.config["AUTH_OPENID_ENABLED"]:
        # register the oauth client
        oauth.register(
            name="auth",
            client_id=app.config["AUTH_CLIENT_ID"],
            client_secret=app.config["AUTH_CLIENT_SECRET"],
            server_metadata_url=app.config["AUTH_SERVER_METADATA_URL"],
            client_kwargs={"scope": "openid profile"},
        )
コード例 #5
0
ファイル: app.py プロジェクト: Jayden-Liang/mypractice
def extent(app):
    oauth.init_app(app)
    csrf.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    return None
コード例 #6
0
        os.mkdir('logs')
    file_handler = RotatingFileHandler('logs/project.log',
                                       maxBytes=10240,
                                       backupCount=10)
    file_handler.setFormatter(
        logging.Formatter(
            '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
        ))
    file_handler.setLevel(logging.INFO)
    app.logger.addHandler(file_handler)

    app.logger.setLevel(logging.INFO)
    app.logger.info('project startup')

# import and register blueprints
app.register_blueprint(frontend)

# init extensions
csrf.init_app(app)
assets.init_app(app)

# register static bundles
assets.register('js_bundle', bundles['js_bundle'])
assets.register('css_bundle', bundles['css_bundle'])


@app.errorhandler(404)
def page_not_found(e):
    # note that we set the 404 status explicitly
    return render_template('404.html'), 404