1:使用pycharm编辑器里面
2:安装django-debug-toolbar
3:进行调试查询
https
django框架调试,各个面板查询消耗时间,pycharm,debug
1:settings.py
INSTALLED_APPS列表中添加
INSTALLED_APPS = [# 使用多合一有点慢# 'multi_captcha_admin',# 多合一验证码'import_export', # 导出excel插件位置'django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles',# [添加django_debug_toolbar][1]# pip install django-debug-toolbar# 4.3.0 (2024-02-01)# 'debug_toolbar','debug_toolbar','app.apps.AppConfig','userprofile.apps.UserprofileConfig', # user表额外一对一表'store.apps.StoreConfig','ownorder.apps.OwnorderConfig','outsourcing.apps.OutsourcingConfig','captcha',# 验证码
]
2:settings.py
MIDDLEWARE 中间件列表中添加
MIDDLEWARE = [# [添加django_debug_toolbar][2]# 'debug_toolbar.middleware.DebugToolbarMiddleware','debug_toolbar.middleware.DebugToolbarMiddleware','django.middleware.security.SecurityMiddleware','django.contrib.sessions.middleware.SessionMiddleware',# 根据系统地区来显示中文还是英文# 'django.middleware.locale.LocaleMiddleware',#'django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware',
]
3.1:settings.py
MIDDLEWARE 中间件列表下方添加
# [添加django_debug_toolbar][3]# from settings03_debug_toolbar import *from .settings03_debug_toolbar import *
3.2:settings03_debug_toolbar.py
主目录中创建settings03_debug_toolbar.py文件
INTERNAL_IPS=['127.0.0.1']
DEBUG_TOOLBAR_PANELS = ['debug_toolbar.panels.history.HistoryPanel','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.panels.profiling.ProfilingPanel',
]
4:urls.py
主目录中的urls.py文件
from django.contrib import admin
from django.urls import path, includeurlpatterns = [path('admin/', admin.site.urls),path('captcha/', include('captcha.urls')),
]# ----------------
# [添加django_debug_toolbar][4]
# 添加django_debug_toolbar需要 from django.urls import include
from .settings import DEBUGif DEBUG:import debug_toolbarurlpatterns = [path('__debug__/', include(debug_toolbar.urls)), ] + urlpatterns
# ----------------