Ejemplo n.º 1
0
def create_app(config_file):
    app = Flask(__name__)

    # configuration settings are loaded from the `config.py` module
    # and (optionally) from a file `XSNIPPET_SETTINGS` env var points to
    app.config.from_pyfile(config_file)
    app.config.from_envvar('XSNIPPET_WEBUI_SETTINGS', silent=True)

    # set jinja2 global vars to be used in all templates
    app.jinja_env.globals.update(
        {
            "title": app.config["TITLE"],
            "abs_url_for": abs_url_for,
            "lang_by_short_name": lang_by_short_name
        }
    )
    # set assets env
    assets.Environment(app)

    app.register_blueprint(webui)

    # register all needed hooks
    app.before_request(create_http_object)

    # create cache connection (it's thread-safe)
    app.cache = create_cache_connection(app, key_prefix="webui_")

    return app
Ejemplo n.º 2
0
def create_app(config_file):
    app = Flask(__name__)

    # configuration settings are loaded from the `config.py` module
    # and (optionally) from a file `XSNIPPET_API_SETTINGS` env var points to
    app.config.from_pyfile(config_file)
    app.config.from_envvar('XSNIPPET_API_SETTINGS', silent=True)

    app.register_blueprint(api)

    # create a database connection (it's thread-safe, so we can keep it global)
    app.db = create_db_connection(app)

    # create a cache connection (it's thread-safe too)
    app.cache = create_cache_connection(app, key_prefix="api_")

    return app