2015-10-12 16:19:05
在网站开发中难免要调试页面,而使用django开发站点时,可以使用django-debug-toolbar来进行调试,安装这个插件很有用,我一开始是为了查看某个页面中所有的context变量值,当然你还可以看到HTTp头、模板、缓存等各种信息,总之很全面也很好用。
以前比较习惯在windows中安装pycharm开发,项目部署在虚拟机中,在本地浏览器中查看效果,这种方式在调试上会有点麻烦,django-debug-toolbar的出现,就解决了这个问题
下面说下如何安装和使用django-debug-toolbar:
1. 安装
使用命令
sudo pip install django-debug-toolbar
安装django-debug-toolbar。(注意Django版本和debug_toolbar的版本兼容问题,没有pip请先安装,参见教程:详解python包管理器pip安装 在settings.py中添加INTERNAL_IPS = ('127.0.0.1',),(从哪些ip访问站点,显示debug_toolbar) 在INSTALLED_APPS 中添加'debug_toolbar' 确保DEBUG选项为true 添加DEBUG_TOOLBAR_PANELS选项 最后设置模板,添加debug_toolbar的模板目录到TEMPLATE_DIRS。 代码如下: 好了,到这里大功即已告成。注意,如果你是为了测试debug_tool创建了一个新的站点,务必要渲染一个模板,让站点有一个可以访问的页面,否 则是得不到debug_tool的界面的。 原文来源:https://m.pythontab.com/article/964 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',
]
共同學(xué)習(xí),寫下你的評(píng)論
評(píng)論加載中...
作者其他優(yōu)質(zhì)文章