def register_extensions(app): from application.extensions import db db.init_app(app) from application.extensions import compress compress.init_app(app) from application.extensions import cache cache.init_app(app)
def configure_extensions(app): # flask-MongoEngine db.init_app(app) db.register_connection(**app.config.get('ORDER_DB_CONFIG')) db.register_connection(**app.config.get('INVENTORY_DB_CONFIG')) db.register_connection(**app.config.get('CART_DB_CONFIG')) db.register_connection(**app.config.get('CONTENT_DB_CONFIG')) db.register_connection(**app.config.get('LOG_DB_CONFIG')) mongo_inventory.init_app(app, config_prefix='MONGO_INVENTORY') redis.connection_pool = ConnectionPool(**app.config.get('REDIS_CONFIG')) session_redis.connection_pool = ConnectionPool( **app.config.get('SESSION_REDIS')) # server side session app.session_interface = RedisSessionInterface(session_redis) # flask-mail mail.init_app(app) mail.app = app # flask-cache cache.init_app(app) # flask-bcrypt bcrypt.init_app(app) # flask-babel babel.init_app(app) # flask-assets assets.init_app(app) # flask_debugtoolbar toolbar.init_app(app) # flask-login (not configured will raise 401 error) login_manager.login_view = 'frontend.login' # login_manager.refresh_view = 'frontend.reauth' @login_manager.user_loader def load_user(id): import application.models as Models return Models.User.objects(id=id, is_deleted=False).first() login_manager.init_app(app) login_manager.login_message = _('Please log in to access this page.') login_manager.needs_refresh_message = _( 'Please reauthenticate to access this page.') # flask-principal (must be configed after flask-login!!!) principal.init_app(app) @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): principal_on_identity_loaded(sender, identity)
def register_extensions(app): assets.init_app(app) bcrypt.init_app(app) cache.init_app(app) db.init_app(app) login_manager.init_app(app) migrate.init_app(app, db) asset_locator.init_app(app) basic_auth.init_app(app) return None
def configure_extensions(app): """ 注册扩展 :param app: :return: """ # --- DB --- # db.init_app(app) # redis.connection_pool = ConnectionPool(**app.config.get('REDIS_CONFIG')) # session_redis.connection_pool = ConnectionPool( # **app.config.get('SESSION_REDIS')) # # # server side session # app.session_interface = RedisSessionInterface(session_redis) # flask-cache cache.init_app(app) # flask-bcrypt bcrypt.init_app(app) # flask-assets assets.init_app(app) # flask_debugtoolbar toolbar.init_app(app) # weixin 注册 # flask-login (not configured will raise 401 error) login_manager.login_view = 'frontend.login' # login_manager.refresh_view = 'frontend.reauth' @login_manager.user_loader def load_user(id): user = Models.SystemUser.query.filter_by(id=id, is_deleted=False).first() return user login_manager.init_app(app) login_manager.login_message = 'Please log in to access this page.' login_manager.needs_refresh_message = 'Please reauthenticate to access this page.' # flask-principal (must be configed after flask-login!!!) principal.init_app(app) @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): principal_on_identity_loaded(sender, identity)
def configure(app, config_name): selected_config = config[config_name or "default"] app.config.from_object(selected_config) app.config.from_envvar("FLASK_CONFIG", silent=True) db.init_app(app) migrate.init_app(app) cache.init_app(app) moment.init_app(app) celery.init_app(app) if selected_config.BUGSNAG_API_KEY: # Configure Bugsnag bugsnag.configure(api_key=selected_config.BUGSNAG_API_KEY, auto_capture_sessions=True) bugsnag.flask.handle_exceptions(app)
def configure_extensions(app): """Configures the extensions.""" # Flask-BabelEx babel.init_app(app) # Captcha Solver captcha_solver.init_app(app) # Flask-Mail mail.init_app(app) # Flask-Admin admin.init_app(app) # Flask-Mongo Engine db.init_app(app) ma.init_app(app) # Flask-Cache cache.init_app(app, config={ 'CACHE_TYPE': 'redis', 'CACHE_KEY_PREFIX': 'UHE', 'CACHE_REDIS_URL': app.config['REDIS_URL'] }) print(app.testing) # Flask-And-Redis # jwt.secret_key = app.config['SECRET_KEY'] redis_store.init_app(app) # Flask-Limiter limiter.init_app(app) # Flask-Allows allows.init_app(app) allows.identity_loader(lambda: current_user) login_manager.init_app(app) # Flask-Plugins app.school_time = Time() oauth.init_app(app) dashboard.bind(app)
def configure(app, config_name): selected_config = config[config_name or "default"] app.config.from_object(selected_config) app.config.from_envvar("FLASK_CONFIG", silent=True) db.init_app(app) migrate.init_app(app) cache.init_app(app) moment.init_app(app) celery.init_app(app) if app.config["SSL_ENABLE"]: # Force https csp = copy.deepcopy(GOOGLE_CSP_POLICY) csp["style-src"] += " 'unsafe-inline'" csp["style-src"] += " platform.twitter.com" csp["style-src"] += " *.twimg.com" csp["frame-src"] += " *.twitter.com" csp["script-src"] += " *.google.com" csp["script-src"] += " platform.twitter.com" csp["script-src"] += " cdnjs.cloudflare.com" csp["script-src"] += " cdn.syndication.twimg.com" csp["script-src"] += " *.gstatic.com" csp["script-src"] += " 'unsafe-inline' 'unsafe-eval'" csp["default-src"] += " *.google-analytics.com" csp["img-src"] = csp["default-src"] csp["img-src"] += " *.twitter.com" csp["img-src"] += " *.twimg.com" csp["img-src"] += " data:" Talisman(app, content_security_policy=csp) if app.config["BUGSNAG_API_KEY"]: # Configure Bugsnag bugsnag.configure(api_key=app.config["BUGSNAG_API_KEY"], auto_capture_sessions=True) bugsnag.flask.handle_exceptions(app)