pip安装
pip install django-debug-toolbar -i http://pypi.douban.com/simple
下面是我在项目中的对debug_toolbar在settings.py中的配置:
首先设置DEBUG = True
1. 在最后一行添加,只能是最后一行,才能对上述的插件进行debug
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware', #debug_toolbar
)
- 配置debug_toolbar的模板路径
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
# os.path.join(REL_SITE_ROOT, 'templates'),
# 'path/to/debug_toolbar/templates' ,
'/home/spang/.virtualenvs/env/lib/python2.7/site-packages/debug_toolbar/templates/',
)
- 导入模块名
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
# Uncomment the next line to enable the admin:
#'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'debug_toolbar', #debug_toolbar
)
- 项目运行的IP
INTERNAL_IPS = ('192.168.1.110',)
- 设置进行debug的对象
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显示的模式
DEBUG_TOOLBAR_CONFIG = {
# Toolbar options
# 'INTERCEPT_REDIRECTS': False,
'JQUERY_URL': '//libs.baidu.com/jquery/1.9.1/jquery.min.js',
}
- 下面设置jQuery位置(默认ajax.google上的jQuery文件,国内不能用)
DEBUG_TOOLBAR_CONFIG = {
# Toolbar options
'JQUERY_URL': '//libs.baidu.com/jquery/1.9.1/jquery.min.js',
}