在 django_debug_toolbar 中,我如何查看提交时的查询

In django_debug_toolbar how can I see the queries on submit

我正在 submit/save 上做一些额外的查询(使用对象属性)(以定义文件 upload_to),我想在 django_debug_toolbar 中看到它们。

我正在为每个文件做同样的查询,我想做一些优化,看看有多少,只是一个调用,或者为每个属性调用。

使用debug_toolbar.panels.sql.SQLPanel。在您的设置文件中:

DEBUG_TOOLBAR_PANELS = [
    'debug_toolbar.panels.versions.VersionsPanel',
    'debug_toolbar.panels.timer.TimerPanel',
    'debug_toolbar.panels.settings.SettingsPanel',
    'debug_toolbar.panels.headers.HeadersPanel',
    'debug_toolbar.panels.request.RequestPanel',
    'debug_toolbar.panels.sql.SQLPanel',  # important one
    'debug_toolbar.panels.staticfiles.StaticFilesPanel',
    'debug_toolbar.panels.templates.TemplatesPanel',
    'debug_toolbar.panels.cache.CachePanel',
    'debug_toolbar.panels.signals.SignalsPanel',
    'debug_toolbar.panels.logging.LoggingPanel',
    'debug_toolbar.panels.redirects.RedirectsPanel',
]

之后,当您 POST 到 URL 并显示一些 HTML 作为结果时,您应该会在调试工具栏中看到一个部分,以查看执行了哪些查询。您可能需要暂时禁用任何重定向,以便获取 POST 而不是重定向 GET 的分析。