本文整理汇总了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