debug_toolbar的安装(转)

Debug_Toolbar 是开发Django应用程序时的必备工具,可以输出详细的调试信息,会话信息,sql语句运行花费时间等,大大方便开发。
到github上下载,根据安装信息安装就行了
下面是我在项目中的对debug_toolbar在settings.py中的配置:
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
)

2,配置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' ,
)

3,导入模块名

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
)

4,项目运行的IP

INTERNAL_IPS = ('192.168.238.1',)

5,设置进行debug的对象

DEBUG_TOOLBAR_PANELS = (
   'debug_toolbar.panels.version.VersionDebugPanel',
   'debug_toolbar.panels.timer.TimerDebugPanel',
   'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel',
   'debug_toolbar.panels.headers.HeaderDebugPanel',
   'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',
   'debug_toolbar.panels.template.TemplateDebugPanel',
   'debug_toolbar.panels.sql.SQLDebugPanel',
   'debug_toolbar.panels.signals.SignalDebugPanel',
   'debug_toolbar.panels.logger.LoggingPanel',
)

6,debug显示的模式

DEBUG_TOOLBAR_CONFIG = {
   'INTERCEPT_REDIRECTS': False,   
}