安装:
cd /home/dev/django-debug-toolbar-1.4
python ./setup.py install
[root@mhtcloud openstack_dashboard]# vi
/usr/share/openstack-dashboard/openstack_dashboard/settings.py
增加红色部分:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
if django.VERSION >= (1, 8, 0):
MIDDLEWARE_CLASSES += (
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',)
else:
MIDDLEWARE_CLASSES += ('django.middleware.doc.XViewMiddleware',)
MIDDLEWARE_CLASSES += (
'horizon.middleware.HorizonMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
…...
INSTALLED_APPS = [
'openstack_dashboard',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django_pyscss',
'openstack_dashboard.django_pyscss_fix',
'compressor',
'horizon',
'openstack_auth',
'debug_toolbar',
]
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',
]
def show_toolbar(request):
return True
DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK" : show_toolbar,
'JQUERY_URL' : "/dashboard/static/horizon/lib/jquery/jquery.min.js",
}
关于
DEBUG_TOOLBAR_CONFIG的更多可用选项,参见:
最后还要打开debug开关:
root@mhtcloud openstack_dashboard]# cat
settings.py | grep DEBUG
DEBUG = False
TEMPLATE_DEBUG = DEBUG
[root@mhtcloud openstack_dashboard]# cat
/etc/openstack-dashboard/local_settings | grep DEBUG
DEBUG = False
TEMPLATE_DEBUG = DEBUG
|
修改
/etc/openstack-dashboard/local_settings:
DEBUG =
True
TEMPLATE_DEBUG =
True
修改
/usr/share/openstack-dashboard/openstack_dashboard/urls.py:
if settings.DEBUG:
import debug_toolbar
urlpatterns += patterns(
'',
url(r'^500/$', 'django.views.defaults.server_error')
,
url(r'^__debug__/', include(debug_toolbar.urls)),
)