为了账号安全,请及时绑定邮箱和手机立即绑定

Django调试工具django-debug-toolbar安装使用教程

标签:
Python
  • 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安装 )

2. 配置

在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的模板目录到TEMPLATE_DIRS。

代码如下:

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',
]

好了,到这里大功即已告成。注意,如果你是为了测试debug_tool创建了一个新的站点,务必要渲染一个模板,让站点有一个可以访问的页面,否 则是得不到debug_tool的界面的。

原文来源:https://m.pythontab.com/article/964


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消