如何查看Django调试工具栏? [英] How do I see the Django debug toolbar?

查看:92
本文介绍了如何查看Django调试工具栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我如何实际看到调试工具栏?还有什么我需要做的吗?
我需要为我的webapp使用一个特定的模板吗?我已经遵循自述文件中的所有步骤,但这还不够 - 似乎还有一些其他的依赖关系,或者其他我所缺少的东西。



另外,当查看我的webapp的一组URL模式时,调试前缀在识别的模式之间找到 。我已经在debug_toolbar中登录了urls.py,以确保模块正在被激活的debug_toolbar应用程序加载,而且它是。



这让我完全神秘,我可以找到没有Google或README的做法,使其真正显示出来,或者要求是什么,所以你可以提供的任何指针都会很棒!



编辑:事实证明,我正在使用运行浏览器的机器到运行Django / Apache的机器的SSH隧道进行测试。在这种情况下,远程机器实际看到的IP地址不是我以为是这样,所以好的IP列表不包含浏览器的远程机器。修正问题!

解决方案


  1. 因为我知道你的HTML页面必须包含封闭身份标签,元标签与 content =text / html


  2. 所有调试工具栏的设置与主设置区分开。所以尝试放在settings.py的末尾,像

      #debug_toolbar设置
    如果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.Sign alsPanel',
    'debug_toolbar.panels.logging.LoggingPanel',
    'debug_toolbar.panels.redirects.RedirectsPanel',
    ]

    DEBUG_TOOLBAR_​​CONFIG = {
    'INTERCEPT_REDIRECTS':False,
    }


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



(注意:Django 1.10之后, MIDDLEWARE_CLASSES 应该是 MIDDLEWARE 。)


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.

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.

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.

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!

解决方案

  1. As I know your HTML page must contain closed body tag, meta tag with content="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

    #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.)

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

这篇关于如何查看Django调试工具栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆