-
python爬虫之Django调试工具django-debug-toolbar安装使用教程
本站最新发布 Python从入门到精通|Python基础教程
试听地址 https://www.xin3721.com/eschool/pythonxin3721/
试听地址 https://www.xin3721.com/eschool/pythonxin3721/
在网站开发中难免要调试页面,而使用django开发站点时,可以使用django-debug-toolbar来进行调试,安装这个插件很有用,我一开始是为了查看某个页面中所有的context变量值,当然你还可以看到HTTp头、模板、缓存等各种信息,总之很全面也很好用。
以前比较习惯在windows中安装pycharm开发,项目部署在虚拟机中,在本地浏览器中查看效果,这种方式在调试上会有点麻烦,django-debug-toolbar的出现,就解决了这个问题
下面说下如何安装和使用django-debug-toolbar:
1. 安装
使用命令
1
|
sudo pip install django-debug-toolbar |
安装django-debug-toolbar。(注意Django版本和debug_toolbar的版本兼容问题,没有pip请先安装,参见教程:详解python包管理器pip安装 )
1
|
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。
代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
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的界面的。
栏目列表
最新更新
如何使用OS模块中的stat方法
Python os 模块
seek() 方法
python打开文件实例1
Python写入文件
什么是流?
文件操作如何进制逐行读取
Python相对路径
with创建临时运行环境
Python文件操作
.Net Standard(.Net Core)实现获取配置信息
Linux PXE + Kickstart 自动装机
Shell 编程 基础
Shell 编程 条件语句
CentOS8-网卡配置及详解
Linux中LVM逻辑卷管理
1.数码相框-相框框架分析(1)
Ubuntu armhf 版本国内源
Linux中raid磁盘阵列
搭建简易网站
access教程之Access简介
mysql 安装了最新版本8.x版本后的报错:
Mysql空间数据&空间索引(spatial)
如何远程连接SQL Server数据库的图文教程
复制SqlServer数据库的方法
搜索sql语句
sql中返回参数的值
sql中生成查询的模糊匹配字符串
数据定义功能
数据操作功能