如何查看Django调试工具栏?

时间:2021-03-05 23:08:55

I have a Django webapp. I have installed the debug_toolbar middleware and module. However, my webapps don't have the debug toolbar pull-out.

我有一个Django webapp。我已经安装了debug_toolbar中间件和模块。但是,我的webapps没有调试工具栏拖出。

How do I actually see the debug toolbar? Is there something more I need to do? Do I need to use a particular template for my webapp? I have followed all the steps in the README, but that is not enough -- there seems to be some other dependency, or something else I'm missing.

我如何看到调试工具栏?我还有什么事要做吗?我需要为我的webapp使用特定的模板吗?我已经完成了自述中所有的步骤,但这还不够——似乎还有一些其他的依赖,或者是我缺少的一些东西。

Also, when looking at the set of URL patterns for my webapp, the debug prefix is not found among the recognized patterns. I've put a log in urls.py in debug_toolbar to make sure that modules is getting loaded by the activated debug_toolbar application, and it is.

此外,当查看我的webapp的URL模式集时,在识别的模式中找不到调试前缀。我在url中写了一个日志。在debug_toolbar中使用py,以确保模块被激活的debug_toolbar应用程序加载,确实如此。

This has me totally mystified, and I can find no Google or README on what to do to make this actually show up, or what the requirements are, so any pointer you can provide would be great!

这让我完全迷惑,我找不到谷歌或自述如何使它实际显示,或要求是什么,所以你能提供的任何指针都将是伟大的!

Edit: It turns out, I was testing this with a SSH tunnel from the machine running the browser to the machine running the Django/Apache. In this case, the IP address actually seen for the remote machine was not what I thought it was, so the list of "good" IPs did not contain the browser's apparent remote machine. Fixing that fixed the problem!

编辑:事实证明,我使用SSH隧道从运行浏览器的机器到运行Django/Apache的机器进行测试。在这种情况下,实际看到的远程机器的IP地址不是我想象的那样,所以“良好”IP列表中没有包含浏览器的明显远程机器。解决这个问题!

1 个解决方案

#1


45  

  1. As I know your HTML page must contain closed body tag, meta tag with content="text/html".

    我知道你的HTML页面必须包含封闭的body标签,meta标签的内容="text/ HTML "。

  2. I prefer the way when all debug-toolbar's settings separed from main settings. So try put in the end of settings.py something like

    我更喜欢所有调试工具栏的设置与主设置分离的方式。所以试着把设置放在最后。py之类的

    #debug_toolbar settings
    if DEBUG:
        INTERNAL_IPS = ('127.0.0.1',)
        MIDDLEWARE_CLASSES += (
            'debug_toolbar.middleware.DebugToolbarMiddleware',
        )
    
        INSTALLED_APPS += (
            'debug_toolbar',
        )
    
        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',
            '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',
        ]
    
        DEBUG_TOOLBAR_CONFIG = {
            'INTERCEPT_REDIRECTS': False,
        }
    

(Edit note: lapis updated the configs above to match the names used by the current (at the time of this update, 1.3.2) version of the Django Debug Toolbar. Per http://django-debug-toolbar.readthedocs.org/en/0.10.0/panels.html, the original versions (that used e.g. debug_toolbar.panels.sql.SQLDebugPanel vs debug_toolbar.panels.sql.SQLPanel as in 1.3.2) were correct when this question was original answered.)

(编辑注意:lapis更新了上面的configs,以匹配当前版本(更新时,1.3.2)Django调试工具栏的名称。根据http://django-debug-toolbar.readthedocs.org/en/0.10.0/panels.html,原始版本(使用例如debug_toolbar.panels.sql)。SQLDebugPanel vs debug_toolbar.panels.sql。当这个问题得到原始答案时,SQLPanel(如1.3.2)是正确的。

(note: after Django 1.10, MIDDLEWARE_CLASSES should be MIDDLEWARE.)

(注意:Django 1.10之后,middleware_class应该是中间件)。

#1


45  

  1. As I know your HTML page must contain closed body tag, meta tag with content="text/html".

    我知道你的HTML页面必须包含封闭的body标签,meta标签的内容="text/ HTML "。

  2. I prefer the way when all debug-toolbar's settings separed from main settings. So try put in the end of settings.py something like

    我更喜欢所有调试工具栏的设置与主设置分离的方式。所以试着把设置放在最后。py之类的

    #debug_toolbar settings
    if DEBUG:
        INTERNAL_IPS = ('127.0.0.1',)
        MIDDLEWARE_CLASSES += (
            'debug_toolbar.middleware.DebugToolbarMiddleware',
        )
    
        INSTALLED_APPS += (
            'debug_toolbar',
        )
    
        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',
            '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',
        ]
    
        DEBUG_TOOLBAR_CONFIG = {
            'INTERCEPT_REDIRECTS': False,
        }
    

(Edit note: lapis updated the configs above to match the names used by the current (at the time of this update, 1.3.2) version of the Django Debug Toolbar. Per http://django-debug-toolbar.readthedocs.org/en/0.10.0/panels.html, the original versions (that used e.g. debug_toolbar.panels.sql.SQLDebugPanel vs debug_toolbar.panels.sql.SQLPanel as in 1.3.2) were correct when this question was original answered.)

(编辑注意:lapis更新了上面的configs,以匹配当前版本(更新时,1.3.2)Django调试工具栏的名称。根据http://django-debug-toolbar.readthedocs.org/en/0.10.0/panels.html,原始版本(使用例如debug_toolbar.panels.sql)。SQLDebugPanel vs debug_toolbar.panels.sql。当这个问题得到原始答案时,SQLPanel(如1.3.2)是正确的。

(note: after Django 1.10, MIDDLEWARE_CLASSES should be MIDDLEWARE.)

(注意:Django 1.10之后,middleware_class应该是中间件)。