python-字典更新序列元素#0的长度为15; 2个为必填项
作者:互联网
我正在将python / django应用程序从1.6.5升级到1.7.我在解决以下错误时遇到麻烦:字典更新序列元素#0的长度为15; 2个为必填项
这是回溯输出:
Request Method: GET
Request URL: http://127.0.0.1:8000/dashboard/
Django Version: 1.7
Python Version: 2.7.5
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.humanize',
'bootstrap3',
'ajax_select',
'appconf',
'versiontools',
'compressor',
'googlecharts',
'django_extensions',
'mandala',
'locations',
'statistics',
'alarms',
'accounts',
'assets')
Installed Middleware:
('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')
Traceback:
File "/Users/CLDSupportSystems/mandala-system/mandala_env_django_1.7/lib/python2.7/sit-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/CLDSupportSystems/mandala-system/mandala_env_django_1.7/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
22. return view_func(request, *args, **kwargs)
File "/Users/CLDSupportSystems/mandala-system/mandala_env_django_1.7/mandala/mandala/views.py" in dashboard
117. return render_to_response('dashboard/dashboard.html', variables,context_instance=RequestContext(request))
File "/Users/CLDSupportSystems/mandala-system/mandala_env_django_1.7/lib/python2.7/site-packages/django/shortcuts.py" in render_to_response
23. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/Users/CLDSupportSystems/mandala-system/mandala_env_django_1.7/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
177. with context_instance.push(dictionary):
File "/Users/CLDSupportSystems/mandala-system/mandala_env_django_1.7/lib/python2.7/site-packages/django/template/context.py" in push
54. return ContextDict(self, *args, **kwargs)
File "/Users/CLDSupportSystems/mandala-system/mandala_env_django_1.7/lib/python2.7/site-packages/django/template/context.py" in __init__
19. super(ContextDict, self).__init__(*args, **kwargs)
Exception Type: ValueError at /dashboard/
Exception Value: dictionary update sequence element #0 has length 15; 2 is required
该错误引发以下行:
return render_to_response('dashboard/dashboard.html', variables,context_instance=RequestContext(request))
这是变量的定义:
variables = RequestContext(request, {
'fresh_locations': fresh_data_locations,
'webalert_locations': webalert_locations,
'locations_reporting': reporting_locations,
'locations_not_reporting': locations_not_reporting,
'inalarm_count': inalarm_count,
'inalarm_stores': inalarm_stores_qs,
'workspace_count': workspace_count,
'user_profile': user_profile,
})
谁能指出我正确的方向?
解决方法:
render_to_response()的第二个参数必须是字典.您传递的是RequestContext().
删除RequestContext()对象,并使变量成为字典:
variables = {
'fresh_locations': fresh_data_locations,
'webalert_locations': webalert_locations,
'locations_reporting': reporting_locations,
'locations_not_reporting': locations_not_reporting,
'inalarm_count': inalarm_count,
'inalarm_stores': inalarm_stores_qs,
'workspace_count': workspace_count,
'user_profile': user_profile,
}
标签:python-2-7,sequence,django-1-7,python,django 来源: https://codeday.me/bug/20191121/2049588.html