Django第三方调试工具django-debug-toolbar
安装pip install django-debug-toolbar修改settings.py中的文件,这个也算是django中的应用INSTALLED_APPS = [\'django.contrib.admin\',\'django.contrib.auth\',\'django.contrib.contenttypes\',\'django.contrib.sessions\',\'django.contrib.messages\',\'django.contrib.staticfiles\',\'debug_toolbar\', #添加这句\'search\']MIDDLEWARE = [\'debug_toolbar.middleware.DebugToolbarMiddleware\', #添加这句\'django.middleware.security.SecurityMiddleware\',\'django.contrib.sessions.middleware.SessionMiddleware\',\'django.middleware.common.CommonMiddleware\',\'django.middleware.csrf.CsrfViewMiddleware\',\'django.contrib.auth.middleware.AuthenticationMiddleware\',\'django.contrib.messages.middleware.MessageMiddleware\',\'django.middleware.clickjacking.XFrameOptionsMiddleware\',]#定义在MIDDLEWARE的下面DEBUG_TOOLBAR_CONFIG = {#引入jQuery库\'JQUERY_URL\':\'https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js\',#工具栏是否折叠\'SHOW_COLLAPSED\':True,#是否显示工具栏\'SHOW_TOOLBAR_CALLBACK\':lambda x:True,}修改urls.pyfrom django.urls import path, include #需要导入from django.conf import settings #需要导入if settings.DEBUG: #在urls.py代码底部加上这段代码import debug_toolbarurlpatterns.insert(0, path(\'__debug__/\', include(debug_toolbar.urls)))
调试之前开发的车辆违章系统
#1对1、多对1外键关联可以通过select_related(\'关联对象\')解决1+N查询问题#多对多外键关联通过prefetch_related(\'关联对象\')解决1+N查询问题