我想使用django-debug-toolbar优化我的查询,问题是我得到了 SQL面板处于活动状态时,每个视图上的"503 Service Unavailable by Daphne"(包括管理员视图)。
注意:当我禁用SQL面板时,所有内容都会立即加载。
有时服务器能够加载页面 (Debug Toolbar in that case),如果只有6个与此视图相关的查询,为什么服务器加载时会出现问题?
检查我的debug.log,我发现服务器抛出了VariableDoesNotExist
[2018-10-25 20:34:19,677] base DEBUG Exception while resolving variable
'trans_status' in template 'debug_toolbar/panels/sql.html'.
Traceback (most recent call last):
File "/home/ubuntu/workspace/.env/local/lib/python2.7/site-packages/django/template/base.py", line 903, in _resolve_lookup
(bit, current)) # missing attribute
VariableDoesNotExist: Failed lookup for key [trans_status] in u'{u\'rgb_color\': [256, 0, 0], u\'stacktrace\': u\'<span class="djdt-path">/home/ubuntu/workspace/.env/local/lib/python2.7/site-packages/channels/management/commands/</span><span class="djdt-file">runserver.py</span> in <span class="djdt-func">run</span>(<span class="djdt-lineno">164</span>)\\n <span class="djdt-code">worker.run()</span>\\n<span class="djdt-path">/home/ubuntu/workspace/.env/local/lib/python2.7/site-packages/channels/</span><span class="djdt-file">worker.py</span> in <span class="djdt-func">run</span>(<span class="djdt-lineno">119</span>)\\n <span class="djdt-code">consumer(message, **kwargs)</span>\\n<span class="djdt-path">/home/ubuntu/workspace/.env/local/lib/python2.7/site-packages/channels/</span><span class="djdt-file">handler.py</span> in <span class="djdt-func">__call__</span>(<span class="djdt-lineno">344</span>)\\n <span class="djdt-code">for reply_message in self.handler(message):</span>\\n<span class="djdt-path">/home/ubuntu/workspace/.env/local/lib/python2.7/site-packages/channels/</span><span class="djdt-file">handler.py</span> in <span class="djdt-func">__call__</span>(<span class="djdt-lineno">214</span>)\\n <span class="djdt-code">response = self.get_response(request)</span>\\n<span class="djdt-path">/home/ubuntu/workspace/.env/local/lib/python2.7/site-packages/channels/</span><span class="djdt-file">staticfiles.py</span> in <span class="djdt-func">get_response</span>(<span class="djdt-lineno">57</span>)\\n <span class="djdt-code">return super(StaticFilesHandler, self).get_response(request)</span>\\n<span class="djdt-path">/home/ubuntu/workspace/.env/local/lib/python2.7/site-packages/django/contrib/sessions/</span><span class="djdt-file">middleware.py</span> in <span class="djdt-func">process_response</span>(<span class="djdt-lineno">58</span>)\\n <span class="djdt-code">request.session.save()</span>\\n<span class="djdt-path">/home/ubuntu/workspace/.env/local/lib/python2.7/site-packages/django/contrib/sessions/backends/</span><span class="djdt-file">db.py</span> in <span class="djdt-func">save</span>(<span class="djdt-lineno">87</span>)\\n <span class="djdt-code">obj.save(force_insert=must_create, force_update=not must_create, using=using)</span>\', u\'vendor\': u\'unknown\', u\'form\': <SQLSelectForm bound=False, valid=Unknown, fields=(sql;raw_sql;params;alias;duration;hash)>, u\'raw_params\': (u\'MTY2ZGEyNzE5Y2I4NzQ4MWE0MjY1NTFhNWZlMDU5ZTQ4ZTA0OWEzNDp7Il9hdXRoX3VzZXJfYmFja2VuZCI6ImRqYW5nby5jb250cmliLmF1dGguYmFja2VuZHMuTW9kZWxCYWNrZW5kIiwid2hvIjoiY29tcGFueSIsInJlYWRudCI6W10sIl9hdXRoX3VzZXJfaGFzaCI6IjgxODdlZjEwZjBkMjkxZDEzOTY2ZGU0MjBjYThlYzhlOTk0OWMyNjEiLCJfYXV0aF91c2VyX2lkIjoiMiJ9\', datetime.datetime(2018, 11, 8, 20, 54, 24, 719902, tzinfo=<UTC>), \'ch0ds40601m4ku1sxp5zrhfqsqjsm1qh\'), u\'start_time\': 1540500864.721914, u\'width_ratio\': 12.230182891935817, u\'start_offset\': 87.76981710806417, u\'is_slow\': False, u\'raw_sql\': u\'UPDATE "django_session" SET "session_data" = %s, "expire_date" = %s WHERE "django_session"."session_key" = %s\', u\'alias\': \'default\', u\'width_ratio_relative\': 99.99999999999993, u\'template_info\': None, u\'stop_time\': 1540500864.723188, u\'is_select\': False, u\'sql\': u\'<strong>UPDATE</strong> "django_session" <strong>SET</strong> "session_data" = 'MTY2ZGEyNzE5Y2I4NzQ4MWE0MjY1NTFhNWZlMDU5ZTQ4ZTA0OWEzNDp7Il9hdXRoX3VzZXJfYmFja2VuZCI6ImRqYW5nby5jb250cmliLmF1dGguYmFja2VuZHMuTW9kZWxCYWNrZW5kIiwid2hvIjoiY29tcGFueSIsInJlYWRudCI6W10sIl9hdXRoX3VzZXJfaGFzaCI6IjgxODdlZjEwZjBkMjkxZDEzOTY2ZGU0MjBjYThlYzhlOTk0OWMyNjEiLCJfYXV0aF91c2VyX2lkIjoiMiJ9', "expire_date" = '2018-11-08T20:54:24.719902+00:00'::timestamptz <strong>WHERE</strong> "django_session"."session_key" = 'ch0ds40601m4ku1sxp5zrhfqsqjsm1qh'\', u\'duration\': 1.2738704681396484, u\'params\': \'["MTY2ZGEyNzE5Y2I4NzQ4MWE0MjY1NTFhNWZlMDU5ZTQ4ZTA0OWEzNDp7Il9hdXRoX3VzZXJfYmFja2VuZCI6ImRqYW5nby5jb250cmliLmF1dGguYmFja2VuZHMuTW9kZWxCYWNrZW5kIiwid2hvIjoiY29tcGFueSIsInJlYWRudCI6W10sIl9hdXRoX3VzZXJfaGFzaCI6IjgxODdlZjEwZjBkMjkxZDEzOTY2ZGU0MjBjYThlYzhlOTk0OWMyNjEiLCJfYXV0aF91c2VyX2lkIjoiMiJ9", "2018-11-08 20:54:24.719902+00:00", "ch0ds40601m4ku1sxp5zrhfqsqjsm1qh"]\', u\'end_offset\': 99.99999999999999, u\'trace_color\': u\'#800080\'}'
https://github.com/encode/django-rest-framework/issues/3736#issuecomment-165506145,这是迄今为止我发现的与该问题有关的唯一评论。
此错误还会通过以下键重复出现:iso_level, duplicate_count, in_trans, ends_trans and starts_trans
。
服务器正在使用python 2.7
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'debug_toolbar',
'rest_framework',
'rest_framework.authtoken',
'oauth2_provider',
'django_extensions',
'channels',
'corsheaders',
...
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR + '/dashboard/templates/default',
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.i18n',
],
},
},
]
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'oauth2_provider.middleware.OAuth2TokenMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'corsheaders.middleware.CorsMiddleware',
]
########################
# Django debug toolbar #
########################
def show_toolbar(request):
return True
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': show_toolbar,
}
requirements.txt
amqp==2.1.4
anyjson==0.3.3
appdirs==1.4.3
asgi-ipc==1.2.0
asgiref==1.1.2
asn1crypto==0.24.0
autobahn==0.17.1
backports.shutil-get-terminal-size==1.0.0
billiard==3.5.0.2
biosppy==0.3.0
celery==4.0.2
certifi==2018.8.24
cffi==1.11.5
channels==1.0.3
chardet==3.0.4
colorama==0.4.0
colorlog==2.10.0
constantly==15.1.0
coverage==4.5.1
cryptography==2.3.1
cycler==0.10.0
daphne==1.0.2
decorator==4.0.10
Django==1.11.16
django-braces==1.9.0
django-cors-headers==2.0.2
django-cors-middleware==1.3.1
django-dbbackup==3.1.3
django-debug-toolbar==1.10.1
django-extensions==1.7.5
django-filter==1.0.2
django-oauth-toolkit==1.0.0
django-suit==0.2.22
djangorestframework==3.8.2
docxtpl==0.5.5
easydev==0.9.37
enum34==1.1.6
fpdf==1.7.2
funcsigs==1.0.2
functools32==3.2.3.post2
gunicorn==19.6.0
hrv==0.1.5
httpie==0.9.4
idna==2.7
incremental==16.10.1
ipaddress==1.0.22
ipdb==0.10.1
ipython==5.1.0
ipython-genutils==0.1.0
Jinja2==2.10
jsonfield==1.0.3
kombu==4.0.2
logging==0.4.9.6
lxml==4.2.5
MarkupSafe==1.0
matplotlib==2.0.0
meld3==1.0.2
mock==2.0.0
msgpack-python==0.4.8
nose==1.3.7
numpy==1.12.0
oauthlib==2.0.2
packaging==16.8
pandas==0.23.4
pathlib2==2.1.0
pbr==2.0.0
pexpect==4.2.1
pickleshare==0.7.4
Pillow==3.4.2
posix-ipc==1.0.0
prompt-toolkit==1.0.8
protobuf==3.2.0
psutil==5.2.0
psycopg2==2.6.2
ptyprocess==0.5.1
pycparser==2.19
Pygments==2.1.3
pyOpenSSL==18.0.0
pyparsing==2.2.0
PyPDF2==1.26.0
python-dateutil==2.6.0
python-docx==0.8.7
python-http-client==2.2.1
pytz==2016.10
PyWavelets==0.5.1
redis==2.10.5
reportlab==3.3.0
requests==2.19.1
rest-condition==1.0.2
scikit-learn==0.18.1
scipy==0.18.1
sendgrid==3.6.0
sendgrid-django==3.0.0
service-identity==17.0.0
setproctitle==1.1.10
simplegeneric==0.8.1
six==1.10.0
sklearn==0.0
spectrum==0.6.6
sqlparse==0.2.4
subprocess32==3.2.7
supervisor==3.2.0
tailer==0.4.1
tensorflow==1.0.0
traitlets==4.3.1
Twisted==16.6.0
txaio==2.6.0
urllib3==1.23
vine==1.1.3
virtualenv==15.0.3
wcwidth==0.1.7
zope.interface==4.3.3