本文整理匯總了Python中flask_debugtoolbar.DebugToolbarExtension方法的典型用法代碼示例。如果您正苦於以下問題:Python flask_debugtoolbar.DebugToolbarExtension方法的具體用法?Python flask_debugtoolbar.DebugToolbarExtension怎麽用?Python flask_debugtoolbar.DebugToolbarExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flask_debugtoolbar
的用法示例。
在下文中一共展示了flask_debugtoolbar.DebugToolbarExtension方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_app
# 需要導入模塊: import flask_debugtoolbar [as 別名]
# 或者: from flask_debugtoolbar import DebugToolbarExtension [as 別名]
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