下载
pip install django-debugtools
用法
1 . 在settings里的INSTALLED_APPS
加入debugtools
。
INSTALLED_APPS += (
'debugtools',
)
2 . 用法有两种。
- 比较简单的用法,是直接在需要打印的页面上面加入这样一句话
{% load debugtools_tags %}
- 另一种用法是在settings里添加这样。
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
# ...
],
'builtins': [ # Add this section
"debugtools.templatetags.debugtools_tags", # Add this line
],
},
},
]
打印
在templates里,用{% print variable1 variable2 %}
可以打印出来想要的变量。
当没有指定变量时{% print %}
,所有上下文变量都会显示。