我已经使用pip安装了Django调试工具栏,并添加了' debug_toolbar'到安装应用程序列表。
当我运行服务器时,工具栏不会显示。我错过了什么步骤?!
答案 0 :(得分:1)
在installation guide之后的2.0.7
中对我有用的是:
pip install -U django
pip install django-debug-toolbar
settings.py
从1.x
迁移到2.x
:我创建了一个虚拟项目:django-admin startproject mysite
,并为mysite\mysite\settings.py
和INSTALLED_APPS
签出了默认的MIDDLEWARE
。剩下的就是添加debug_toolbar
:
# As mentioned in the last step of Installation Guide
INTERNAL_IPS = ['127.0.0.1', '::1']
# Default config + some changes
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'debug_toolbar', # Add this
'mysite', # Your app
]
# Default config + some changes
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware', # Add this
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
再次,只需遵循Installation Guide并将其添加到URL配置中即可:
from django.conf import settings
from django.conf.urls import include, url
if settings.DEBUG:
import debug_toolbar
urlpatterns = [
url(r'^__debug__/', include(debug_toolbar.urls)),
] + urlpatterns