Django2.0之调试利器django-debug-toolbar

1. 安装Debug Toolbar

pip install django-debug-toolbar
2. settings.py
DEBUG = True
INSTALLED_APPS = [
# …
‘django.contrib.staticfiles’,
# …
‘debug_toolbar’,
]
3. 中间件:
【Django2.0之调试利器django-debug-toolbar】MIDDLEWARE = [
# …
‘debug_toolbar.middleware.DebugToolbarMiddleware’,
# …
]
4. settigs.py最后一行:
DEBUG_TOOLBAR_CONFIG={‘JQUERY_URL’: r”http://code.jquery.com/jquery-2.1.1.min.js“}
或者:在python的site-packages找到debug_toolbar包,编辑settings.py:
CONFIG_DEFAULTS = {
Toolbar options ‘DISABLE_PANELS’: set([‘debug_toolbar.panels.redirects.RedirectsPanel’]),
‘INSERT_BEFORE’: ‘’,
‘JQUERY_URL’: ‘//cdn.bootcss.com/jquery/2.1.4/jquery.min.js’, #替换成这样就好了~~
‘RENDER_PANELS’: None,
‘RESULTS_CACHE_SIZE’: 10,
‘ROOT_TAG_EXTRA_ATTRS’: ”,
‘SHOW_COLLAPSED’: False,
‘SHOW_TOOLBAR_CALLBACK’: ‘debug_toolbar.middleware.show_toolbar’,
Panel options ‘EXTRA_SIGNALS’: [],
‘ENABLE_STACKTRACES’: True,
‘HIDE_IN_STACKTRACES’: (
‘socketserver’ if six.PY3 else ‘SocketServer’,
‘threading’,
‘wsgiref’,
‘debug_toolbar’,
‘django’,
),
‘PROFILER_MAX_DEPTH’: 10,
‘SHOW_TEMPLATE_CONTEXT’: True,
‘SQL_WARNING_THRESHOLD’: 500, # milliseconds
INTERNAL_IPS = (‘127.0.0.1’,)
5. urls.py:
urlpatterns = [url(r’^__debug__/’, include(debug_toolbar.urls)), ] + urlpatterns
这句不配置会报djdt找不到错误!!!如图:
Django2.0之调试利器django-debug-toolbar
文章图片

大功告成!!!
Django2.0之调试利器django-debug-toolbar
文章图片

参考文章:
https://blog.csdn.net/babados/article/details/77943642
https://www.cnblogs.com/Lands-ljk/p/5506766.html

    推荐阅读