【问题标题】:In django_debug_toolbar how can I see the queries on submit在 django_debug_toolbar 我如何查看提交时的查询
【发布时间】:2018-01-28 15:56:31
【问题描述】:

我在提交/保存(定义文件upload_to)时做了一些额外的查询(使用对象属性),我想在django_debug_toolbar中看到它们。

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

【问题讨论】:

  • 为什么不能使用 IDE 调试器来追踪这个?
  • 不知道有没有可能——我有Pycharm;我想知道数据库和查询中的真实调用次数

标签: django django-debug-toolbar


【解决方案1】:

使用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',
]

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

【讨论】:

  • 禁用重定向解决了我在管理员中看不到任何更新/插入的问题。
猜你喜欢
  • 2022-09-22
  • 2022-11-19
  • 2017-11-19
  • 2014-01-28
  • 1970-01-01
  • 1970-01-01
  • 2013-11-15
  • 1970-01-01
  • 2011-02-26
相关资源
最近更新 更多