gpt4 book ai didi

python - 字典更新序列元素 #0 的长度为 15; 2 是必需的

转载 作者:行者123 更新时间:2023-11-28 16:35:49 26 4
gpt4 key购买 nike

我正在将我的 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 只是一个字典:

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 - 字典更新序列元素 #0 的长度为 15; 2 是必需的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26407842/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com