def create_app(config_name): # app init app = Flask(__name__) # config init app.config.from_object(config[config_name]) config[config_name].init_app(app) # extensions init triangle.init_app(app) bootstrap.init_app(app) mail.init_app(app) moment.init_app(app) db.init_app(app) login_manager.init_app(app) pagedown.init_app(app) # debug toolbar init flask_debugtoolbar.DebugToolbarExtension(app) # =======================# # Blueprint Registration # # =======================# from .main import main as main_blueprint app.register_blueprint(main_blueprint) from .auth import auth as auth_blueprint app.register_blueprint(auth_blueprint, url_prefix='/auth') from .api import api as api_blueprint app.register_blueprint(api_blueprint, url_prefix='/api/v1.0') return app
def init_app(app): app.register_blueprint(blueprint) pages.init_app(app) Fleem(app, loaders=[ instance_theme_loader, theme_manager.packaged_themes_loader, theme_manager.theme_paths_loader ]) if dbt is not None: dbt.DebugToolbarExtension(app)
def debug_app(app): """Add the debug toolbar extension to the application.""" app.jinja_env.undefined = jinja2.StrictUndefined try: import flask_debugtoolbar except ImportError: flask_debugtoolbar = None else: app.config['SECRET_KEY'] = 'debug-secret-key' flask_debugtoolbar.DebugToolbarExtension(app)
def get_blueprint(): """ Mandatory interface and factory function. This function must return a valid instance of :py:class:`mydojo.base.MyDojoBlueprint` or :py:class:`flask.Blueprint`. """ hbp = DevtoolsBlueprint(BLUEPRINT_NAME, __name__, template_folder='templates', url_prefix='/{}'.format(BLUEPRINT_NAME)) hbp.developer_toolbar = flask_debugtoolbar.DebugToolbarExtension() # pylint: disable=locally-disabled,attribute-defined-outside-init hbp.register_view_class(ConfigView, '/config') return hbp
def configure_app(app): app.config["JINJA_LSTRIP_BLOCKS"] = False app.config["JINJA_TRIM_BLOCKS"] = False app.config.from_envvar("GOGDB_CONFIG") app.jinja_env.lstrip_blocks = app.config["JINJA_LSTRIP_BLOCKS"] app.jinja_env.trim_blocks = app.config["JINJA_TRIM_BLOCKS"] if app.debug: try: import flask_debugtoolbar app.config["SECRET_KEY"] = os.urandom(24) toolbar = flask_debugtoolbar.DebugToolbarExtension(app) except ImportError: pass
def init_ext(app): app.config['secret_key'.upper()] = '120' app.config['session_type'.upper()] = 'redis' Session(app=app) db.init_app(app=app) migrate = Migrate() migrate.init_app(app=app, db=db) Bootstrap(app=app) app.debug = True dtb = flask_debugtoolbar.DebugToolbarExtension() dtb.init_app(app=app) # 如果报错 NO models name flask.extends cache.init_app(app=app)
} # Load configuration from the environment if available for key, value in default_config.items(): app.config[key] = os.environ.get(key, value) # Base application flask_bootstrap.Bootstrap(app) db = flask_sqlalchemy.SQLAlchemy(app) migrate = flask_migrate.Migrate(app, db) limiter = flask_limiter.Limiter(app, key_func=lambda: current_user.username) # Debugging toolbar if app.config.get("DEBUG"): import flask_debugtoolbar toolbar = flask_debugtoolbar.DebugToolbarExtension(app) # Profiler if app.config.get("DEBUG"): app.wsgi_app = profiler.ProfilerMiddleware(app.wsgi_app, restrictions=[30]) # Manager commnad manager = flask_script.Manager(app) manager.add_command('db', flask_migrate.MigrateCommand) # Babel configuration babel = flask_babel.Babel(app) translations = list(map(str, babel.list_translations())) @babel.localeselector
def create_app(app_env=None): app = flask.Flask('steam_friends') # load main configs try: app_env = app_env or os.environ['SF_ENV'] app_config = config.configs[app_env] except KeyError: # print because logging can't be setup yet print("ERROR: You must `export SF_ENV` to one of: {}".format(', '.join(config.configs.iterkeys())), file=sys.stderr) sys.exit(1) app.config.from_object(app_config) # allow loading additional configuration # secret things like passwords and API keys are loaded here app.config.from_envvar('SF_CONFIG', silent=True) # anything can also come from env vars # SECRETS can only come from environment variables for key, value in os.environ.iteritems(): if key.startswith('SF_'): config_key = key[len('SF_'):] # I don't love this... if value == 'True': value = True elif value == 'False': value = False app.config[config_key] = value # all secrets should have been replaced with real values. check for any missed ones for key, value in app.config.iteritems(): if key == config.SECRET: raise ValueError("SF_{} not set!" % key) ext.flask_celery.init_app(app) ext.flask_redis.init_app(app) ext.oid.init_app(app) # attach our blueprints map(app.register_blueprint, [ auth.blueprint, main.blueprint, ]) app.register_blueprint(api.blueprint, url_prefix='/api') # setup application wide error handlers # other error handlers should be attached to their respective blueprints # TODO: i think new flask changed this # app.error_handler_spec[None][500] = main.internal_error # dev only things go here if app.debug: flask_debugtoolbar.DebugToolbarExtension(app) # delete flask's default handlers. https://github.com/mitsuhiko/flask/issues/641 # we configure our own logging when we want it del app.logger.handlers[:] return app