flask 程序性能分析debugtoolbar/慢查询(flask 109)

2019-08-20 11:02:22 浏览数 (1)

image.png

from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_debugtoolbar import DebugToolbarExtension

from config import SQLALCHEMY_DATABASE_URI, SQLALCHEMY_TRACK_MODIFICATIONS, SECRET_KEY

db = SQLAlchemy()

toolbar = DebugToolbarExtension()

def create_app(): app = Flask(name) app.debug = True app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = SQLALCHEMY_TRACK_MODIFICATIONS app.config['SECRET_KEY'] = 'TTC'

代码语言:javascript复制
db.init_app(app=app)
toolbar.init_app(app)
return app

开启慢查询

SQLALCHEMY_RECORD_QUERIES=True

打印出慢查询的语句

image.png

image.png

0 人点赞