请摒弃简单粗暴的print
--马云
我比较习惯在windows中安装pycharm开发,项目部署在虚拟机中,在本地浏览器中查看效果,这种方式在调试上会有点麻烦,django-debug-toolbar的出现,就解决了这个问题
一、步骤
- 使用sudo pip install django-debug-toolbar安装django-debug-toolbar。(注意Django版本和debug_toolbar的版本兼容问题)
- 在settings.py中添加'debug_toolbar.middleware.DebugToolbarMiddleware'到项目的MIDDLEWARE_CLASSES 内。
- 在settings.py中添加INTERNAL_IPS = ('127.0.0.1',),(从哪些ip访问站点,显示debug_toolbar)
- 在INSTALLED_APPS 中添加'debug_toolbar'
- 确保DEBUG选项为true
- 添加DEBUG_TOOLBAR_PANELS选项
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',
]
最后的效果图:
更多信息请:django debug toolbar官方文档1.1版本 注意版本的兼容