Python flask_debugtoolbar.DebugToolbarExtension() Examples

The following are 1 code examples of flask_debugtoolbar.DebugToolbarExtension(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask_debugtoolbar , or try the search function .
Example #1
Source File: __init__.py    From Arsenal with GNU General Public License v3.0 4 votes vote down vote up
def create_app(**config_overrides):
    """
    Creates a flask application with the desired configuration settings
    and connects it to the database.
    """
    app = Flask(__name__)

    # Initialize logging
    _configure_logging()

    # Initialize configuration
    app.config.from_object("teamserver.config")
    app.config["MODE"] = MODE

    app.config["MONGODB_SETTINGS"] = {"db": DB_NAME, "host": DB_HOST, "port": DB_PORT}
    if DB_USER and DB_PASS:
        app.config["MONGODB_SETTINGS"]["username"] = DB_USER
        app.config["MONGODB_SETTINGS"]["password"] = DB_PASS

    app.config["CELERY_BROKER_URL"] = CELERY_BROKER_URL
    app.config["CELERY_RESULT_BACKEND"] = CELERY_RESULT_BACKEND

    # Override configuration options
    app.config.update(config_overrides)

    # Initialize DEBUG
    if MODE.upper() == "DEBUG":
        # Enable debug logging
        app.logger.setLevel(logging.DEBUG)

        # Enable profiling
        from werkzeug.contrib.profiler import ProfilerMiddleware

        app.config["PROFILE"] = True
        app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[50], profile_dir=PROFILE_DIR)

        # Enable mongodb debug toolbar
        from flask_debugtoolbar import DebugToolbarExtension

        app.config["DEBUG_TB_PANELS"] = ["flask_mongoengine.panels.MongoDebugPanel"]
        app.debug_toolbar = DebugToolbarExtension(app)
    else:
        app.logger.setLevel(logging.WARNING)

    # Initialize the database
    try:
        DB.init_app(app)
    except MongoEngineConnectionError as conn_err:
        print(conn_err)
        sys.exit("Could not connect to database.")

    # Import endpoints
    from teamserver.router import API

    app.register_blueprint(API)

    app.logger.info(f"Initialized Arsenal Teamserver [{MODE}]")
    return app