我最近安装了 django-debug-toolbar。工具栏有效,我可以看到侧面的选项卡。但是,即使我显然已经执行了 SQL 查询(例如在管理员中),SQL 选项卡中也没有显示任何内容:
我的设置如下:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2'
'NAME': 'mydatabase'
....
}
}
# Backwards compatability with apps
DATABASE_ENGINE = DATABASES['default']['ENGINE'].split('.')[-1]
DATABASE_NAME = DATABASES['default']['NAME']
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',
)
INSTALLED_APPS = (
...
'debug_toolbar',
...
)
# Settings for the django-debug-toolbar
DEBUG_TOOLBAR_PANELS = (
'debug_toolbar.panels.version.VersionDebugPanel',
'debug_toolbar.panels.cache.CacheDebugPanel',
'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',
)
def custom_show_toolbar(request):
return request.user.is_staff
DEBUG_TOOLBAR_CONFIG = {
'INTERCEPT_REDIRECTS':False,
'SHOW_TOOLBAR_CALLBACK':custom_show_toolbar,
'SHOW_TEMPLATE_CONTEXT':True,
'HIDE_DJANGO_SQL':False,
}
我正在使用带有工具栏版本 0.8.5 的 Django 1.3。对这个问题的任何帮助都会很棒......
编辑: 根据答案,我决定发布我如何处理我的视图功能:
def func1(query, var1):
query = query.filter(var__icontains=var1)
return query
def func2(query, var2):
query = query.filter(var__icontains=var2)
return query
def parse(**kwargs):
# Based on some logic call func1 and func2
return query
def view(request, template="display.html"):
# Do some request processing
query = parse(request.GET.items())
return render(request, template, { 'items':list(query) })