def create_app(config_filename): """ Flask application factory :param config_filename: Config to use :returns: Flask app instance """ app = Flask(__name__) app.config.from_object(config_filename) db.init_app(app) ma.init_app(app) jwt.init_app(app) migrate.init_app(app, db) # logging.config.fileConfig('application/logging.config') # logging.getLogger('sysLogLogger').critical('critical message') for installed_app in app.config['INSTALLED_APPS']: view = importlib.import_module('views.{}'.format(installed_app)) app.register_blueprint(view.blueprint) # get_config_args(app) return app
def register_extensions(app): from application.extensions import db db.init_app(app) from application.extensions import migrate migrate.init_app(app=app) from application.extensions import OAuth oauth = OAuth(app) auth0 = oauth.register( 'auth0', client_id=app.config['AUTH0_CLIENT_ID'], client_secret=app.config['AUTH0_CLIENT_SECRET'], api_base_url=app.config['AUTH0_BASE_URL'], access_token_url=f"{app.config['AUTH0_BASE_URL']}/oauth/token", authorize_url=f"{app.config['AUTH0_BASE_URL']}/authorize", client_kwargs={ 'scope': 'openid profile', }, ) app.config['auth0'] = auth0 from application.extensions import DebugToolbarExtension DebugToolbarExtension(app)
def register_extensions(app): from application.extensions import db db.init_app(app) from application.models import PlanningAuthority from application.extensions import migrate migrate.init_app(app=app) from flask_sslify import SSLify sslify = SSLify(app) from application.extensions import OAuth oauth = OAuth(app) auth0 = oauth.register( 'auth0', client_id=app.config['AUTH0_CLIENT_ID'], client_secret=app.config['AUTH0_CLIENT_SECRET'], api_base_url=app.config['AUTH0_BASE_URL'], access_token_url=f"{app.config['AUTH0_BASE_URL']}/oauth/token", authorize_url=f"{app.config['AUTH0_BASE_URL']}/authorize", client_kwargs={ 'scope': 'openid profile', }, ) app.config['auth0'] = auth0
def register_extensions(app): from application.extensions import db db.init_app(app) from application.models import LocalAuthority from application.extensions import migrate migrate.init_app(app=app)
def register_extensions(app): from application.extensions import db db.app = app db.init_app(app) with app.app_context(): db.create_all()
def registe_extensions(app): """config extensions""" db.init_app(app) migrate.init_app(app, db) login_manager.init_app(app) @login_manager.user_loader def load_user(user_id): return User.query.filter_by(id=user_id).first()
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): from flask_sslify import SSLify SSLify(app) from application.extensions import db db.init_app(app) from application.models import Cache from application.extensions import migrate migrate.init_app(app=app)
def db_session(app): """ Provide the transactional fixtures with access to the database via a Flask-SQLAlchemy database connection. """ with app.app_context() as ctx: ctx.push() db.init_app(app) yield db.session db.session.close()
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 register_extensions(app): db.init_app(app) login_manager.init_app(app) login_manager.login_view = 'auth.login' @login_manager.user_loader def load_user(user_id): return User.objects(id=user_id).first() admin.init_app(app) admin.add_view(ModelView(Role))
def register_extensions(app): from application.extensions import misaka from application.extensions import db from application.extensions import migrate misaka.init_app(app) db.init_app(app) migrate.init_app(app) if os.environ.get('FLASK_ENV') == 'production': from flask_sslify import SSLify SSLify(app)
def create_app(config_class=Config): app.config.from_object(config_class) from application import controllers from application.models import db, User from application.admin import init_admin db.init_app(app) migrate.init_app(app, db) csrf.init_app(app) login_manager.init_app(app) init_admin(app) authentication(User) return app
def extensions(app): """ Register 0 or more extensions (mutates the app passed in). :param app: Flask application instance :return: None """ db.init_app(app) login_manager.init_app(app) migrate.init_app(app, db) 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 create_app(config_class=Config): app.config.update(api_spec) app.config.from_object(config_class) from application.models import db from application.admin import init_admin db.init_app(app) migrate.init_app(app, db) admin_manager.init_app(app) init_admin(admin_manager) jwt.init_app(app) docs.init_app(app) register_blueprints(app) register_routes(docs) return app
def register_extensions(app): from application.extensions import db from application.extensions import login from application.extensions import migrate from application.extensions import mail from application.extensions import babel from application.extensions import csrf csrf._exempt_views.add('dash.dash.dispatch') db.init_app(app) login.init_app(app) login.login_view = "auth.login" migrate.init_app(app, db) mail.init_app(app) babel.init_app(app) csrf.init_app(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 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 register_extensions(app): db.init_app(app) migrate.init_app(app, db) babel.init_app(app) swagger.init_app(app) flask_wtf.CSRFProtect(app) # Setup Flask-Security from application.models.authbase import User, Role # from application.forms.user import ExtendedLoginForm user_datastore = SQLAlchemyUserDatastore(db, User, Role) security.init_app( app, datastore=user_datastore, # login_form=ExtendedLoginForm, # register_form=ExtendedRegisterForm )
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 app(): """ Creates a Postgres database and Flask app context for the tests and drops the database when all tests are done """ client = Flask(__name__) postgres = PostgresImage(port=55432, alembic_config=root_dir.joinpath( "migrations", "alembic.ini").as_posix()) client.config['SQLALCHEMY_DATABASE_URI'] = postgres.connection_details with client.app_context(): # initial run requires the SQLAlchemy and migration instance to be initialized as these objects # will be used to migrate the database in the postgres.run() method db.init_app(client) migrate.init_app(client, db) postgres.run() yield client postgres.close()
def register_extensions(app): """Register models.""" db.init_app(app) login_manager.init_app(app) # flask-admin configs admin.init_app(app) admin.add_view(ModelView(User)) admin.add_view(ModelView(Role)) login_manager.login_view = 'auth.login' @login_manager.user_loader def load_user(user_id): return User.objects(id=user_id).first() # jwt config def jwt_authenticate(username, password): logging.info("username:{}\npassword:{}\n".format(username, password)) user = User.objects(name=username, password=password).first() return user def jwt_identity(payload): logging.info("payload:{}".format(payload)) user_id = payload['identity'] return User.objects(id=user_id).first() def make_payload(identity): iat = datetime.utcnow() exp = iat + current_app.config.get('JWT_EXPIRATION_DELTA') nbf = iat + current_app.config.get('JWT_NOT_BEFORE_DELTA') identity = str(identity.id) return {'exp': exp, 'iat': iat, 'nbf': nbf, 'identity': identity} jwt.authentication_handler(jwt_authenticate) jwt.identity_handler(jwt_identity) jwt.jwt_payload_handler(make_payload) jwt.init_app(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)
def register_extensions(app): db.init_app(app) migrate.init_app(app, db) return None
def register_extensions(app: Flask) -> None: from application.extensions import login, db login.init_app(app) db.init_app(app)
def init_extensions(app): db.init_app(app)
from application.extensions import db, login_manager, babel, admin, principal from configs.config import BaseConfig from application.services.permission import principal_on_identity_loaded from flask_principal import identity_loaded app = Flask(__name__) #admin app.register_blueprint(manage_items) #website app.register_blueprint(auth) app.register_blueprint(address) db.init_app(app) babel.init_app(app) app.config.from_object(BaseConfig()) db.register_connection(**app.config.get('USER_DB_CONFIG')) db.register_connection(**app.config.get('DATA_DB_CONFIG')) db.register_connection(**app.config.get('INVENTORY_DB_CONFIG')) login_manager.init_app(app) login_manager.login_view = 'frontend.login' @login_manager.user_loader def load_user(id): import application.models as Models return Models.User.objects(id=id, is_deleted=False).first()
def register_extensions(app): from application.extensions import db db.init_app(app)
def register_extensions(app): """Register Flask extensions.""" db.init_app(app) migrate.init_app(app, db) return None
def register_extensions(app): db.init_app(app)
def register_extensions(app): db.init_app(app) migrate.init_app(app, db) api_scaffold.init_app(app, db, auth) return None