debug_toolbar

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

安装命令:

pip install django-debug-toolbar -i https://pypi.tuna.tsinghua.edu.cn/simple/

前置;

	INSTALLED_APP中添加'django.contrib.staticfiles',
	"INSTALLED_APP中添加'debug_toolbar',
	debug_toolbar放在django.contrib.staticfiles之后"
	settings中添加STATIC_URL

在项目路径下的跟urls.py文件中添加:
若是调试模式则添加debug_toolbar中的部分路由

if settings.DEBUG:
    import debug_toolbar
    urlpatterns = [
        re_path('__debug__/', include(debug_toolbar.urls))
    ] + urlpatterns

在settings.py的MIDDLEWARE中添加,尽量放置在前面

'debug_toolbar.middleware.DebugToolbarMiddleware',

在 settings中添加配置

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

在settings中设置可以看到debug模式的访问ip

INTERNAL_IPS = ('192.168.31.205', '0.0.0.0', 'localhost', '127.0.0.1')
上一篇:Android MD风格相关控件小结


下一篇:一手遮天 Android - view(弹出类): ContextMenu 基础