在控制台安装:
pip install django-debug-toolbar==3.7
pip install -i https://mirrors.aliyun.com/pypi/simple/ django-debug-toolbar-request-history
setting.py里需要配置以下内容
# 引用debug_toolbar app
INSTALLED_APPS = [
'debug_toolbar',
]
# 引用debug_toolbar.middleware.DebugToolbarMiddleware
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
]
# 增加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,jquery
DEBUG_TOOLBAR_CONFIG = {
# 访问本地jquery文件
"JQUERY_URL": '',
# 已存储请求的数量
'RESULTS_STORE_SIZE': 100,
}
STATIC_URL = '/static/'
#调试主机IP,哪个主机进行调试就写那个主机的IP
INTERNAL_IPS = [
'127.0.0.1',
'192.168.224.1',
]
urls.py里需要配置以下内容
from django.conf import settings
from django.contrib import admin
from django.urls import include, path
if settings.DEBUG:
import debug_toolbar
urlpatterns = [
path('__debug__/', include(debug_toolbar.urls)),
path('admin/', admin.site.urls),
]