zoukankan      html  css  js  c++  java
  • Django调试工具django-debug-toolbar安装使用教程

    在网站开发中难免要调试页面,而使用django开发站点时,可以使用django-debug-toolbar来进行调试,安装这个插件很有用,我一开始是为了查看某个页面中所有的context变量值,当然你还可以看到HTTp头、模板、缓存等各种信息,总之很全面也很好用。

    以前比较习惯在windows中安装pycharm开发,项目部署在虚拟机中,在本地浏览器中查看效果,这种方式在调试上会有点麻烦,django-debug-toolbar的出现,就解决了这个问题

    下面说下如何安装和使用django-debug-toolbar:

    1. 安装

    使用命令

    1
    sudo pip install django-debug-toolbar

    安装django-debug-toolbar。(注意Django版本和debug_toolbar的版本兼容问题,没有pip请先安装,参见教程:‍详解python包管理器pip安装‍ ‍)

    1
    2. 配置

    在settings.py中添加'debug_toolbar.middleware.DebugToolbarMiddleware'到项目的MIDDLEWARE_CLASSES 内。

    在settings.py中添加INTERNAL_IPS = ('127.0.0.1',),(从哪些ip访问站点,显示debug_toolbar)

    在INSTALLED_APPS 中添加'debug_toolbar'

    确保DEBUG选项为true

    添加DEBUG_TOOLBAR_PANELS选项

    最后设置模板,添加debug_toolbar的模板目录到TEMPLATE_DIRS。

    代码如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    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_tool创建了一个新的站点,务必要渲染一个模板,让站点有一个可以访问的页面,否 则是得不到debug_tool的界面的。

    http://www.qytang.com/cn/list/28/389.htm
    http://www.qytang.com/cn/list/28/388.htm
    http://www.qytang.com/cn/list/28/362.htm
    http://www.qytang.com/cn/list/28/358.htm
    http://www.qytang.com/cn/list/28/351.htm
    http://www.qytang.com/cn/list/28/348.htm
    http://www.qytang.com/cn/list/28/340.htm
    http://www.qytang.com/cn/list/28/338.htm
    http://www.qytang.com/cn/list/28/336.htm
    http://www.qytang.com/cn/list/28/330.htm

    http://www.qytang.com

  • 相关阅读:
    原生JS---2
    PHP中include和require绝对路径、相对路径问题
    魔方(小玩具)
    html5技术介绍
    苹果电脑 快捷键
    写代码的心得,怎么减少编程中的 bug?
    http状态代码含义表
    开源项目
    蓝牙 CoreBluetooth
    减小iOS应用程序的大小
  • 原文地址:https://www.cnblogs.com/qytang/p/5534525.html
Copyright © 2011-2022 走看看