zoukankan      html  css  js  c++  java
  • Django中使用django_debug_toolbar

    一 概述

    django_debug_toolbar 是django的第三方工具包,给django扩展了调试功能。 
    包括查看执行的sql语句,db查询次数,request,headers,调试概览等。 

    二、安装

    使用django_debug_toolbar工具先使用pip安装。 
    pip install django_debug_toolbar,然后修改settings.pyurls.py文件。

    三、修改settings文件

    1. 显示设置调试工具不要调整settings中的设置

    1 DEBUG_TOOLBAR_PATCH_SETTINGS = False

    2. 添加调试工具App

    1 INSTALLED_APPS = INSTALLED_APPS + (
    2     'debug_toolbar.apps.DebugToolbarConfig',
    3 )

    3. 添加调试工具中间件

    1 MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + (
    2     'debug_toolbar.middleware.DebugToolbarMiddleware',
    3 )

    4. 添加调试工具的IP

    1 INTERNAL_IPS = ("127.0.0.1",)

    5. debug_toolbar 组件选项

    默认值为如下12个组件,可根据需要自行调整。此处不写代表使用默认值。

     1 DEBUG_TOOLBAR_PANELS = [
     2     'debug_toolbar.panels.versions.VersionsPanel',
     3     'debug_toolbar.panels.timer.TimerPanel',
     4     'debug_toolbar.panels.settings.SettingsPanel',
     5     'debug_toolbar.panels.headers.HeadersPanel',
     6     'debug_toolbar.panels.request.RequestPanel',
     7     'debug_toolbar.panels.sql.SQLPanel',
     8     'debug_toolbar.panels.staticfiles.StaticFilesPanel',
     9     'debug_toolbar.panels.templates.TemplatesPanel',
    10     'debug_toolbar.panels.cache.CachePanel',
    11     'debug_toolbar.panels.signals.SignalsPanel',
    12     'debug_toolbar.panels.logging.LoggingPanel',
    13     'debug_toolbar.panels.redirects.RedirectsPanel',
    14 ]

    6. debug_toolbar 配置项

    默认为如下选项,此处不写代表使用默认值,可根据需要自行调整。 
    备注:'JQUERY_URL': '//cdn.bootcss.com/jquery/2.1.4/jquery.min.js'此项原本为google指向的一个js,改成这样就不会报404了。

     1 CONFIG_DEFAULTS = {
     2     # Toolbar options
     3     'DISABLE_PANELS': {'debug_toolbar.panels.redirects.RedirectsPanel'},
     4     'INSERT_BEFORE': '</body>',
     5     'JQUERY_URL': '//cdn.bootcss.com/jquery/2.1.4/jquery.min.js',
     6     'RENDER_PANELS': None,
     7     'RESULTS_CACHE_SIZE': 10,
     8     'ROOT_TAG_EXTRA_ATTRS': '',
     9     'SHOW_COLLAPSED': False,
    10     'SHOW_TOOLBAR_CALLBACK': 'debug_toolbar.middleware.show_toolbar',
    11     # Panel options
    12     'EXTRA_SIGNALS': [],
    13     'ENABLE_STACKTRACES': True,
    14     'HIDE_IN_STACKTRACES': (
    15         'socketserver' if six.PY3 else 'SocketServer',
    16         'threading',
    17         'wsgiref',
    18         'debug_toolbar',
    19         'django',
    20     ),
    21     'PROFILER_MAX_DEPTH': 10,
    22     'SHOW_TEMPLATE_CONTEXT': True,
    23     'SKIP_TEMPLATE_PREFIXES': (
    24         'django/forms/widgets/',
    25         'admin/widgets/',
    26     ),
    27     'SQL_WARNING_THRESHOLD': 500,   # milliseconds
    28 }

    四 修改urls文件

    debug_toolbar添加到全局url

    if settings.DEBUG:
    import debug_toolbar
    urlpatterns = [
    path('__debug__/', include(debug_toolbar.urls)),
    ] + urlpatterns
  • 相关阅读:
    URAL 2067 Friends and Berries (推理,数学)
    URAL 2070 Interesting Numbers (找规律)
    URAL 2073 Log Files (模拟)
    URAL 2069 Hard Rock (最短路)
    URAL 2068 Game of Nuts (博弈)
    URAL 2066 Simple Expression (水题,暴力)
    URAL 2065 Different Sums (找规律)
    UVa 1640 The Counting Problem (数学,区间计数)
    UVa 1630 Folding (区间DP)
    UVa 1629 Cake slicing (记忆化搜索)
  • 原文地址:https://www.cnblogs.com/harryblog/p/10207674.html
Copyright © 2011-2022 走看看