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

标签 python django python-2.7 sequence django-1.7

我正在将我的 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/

相关文章:

python - Django Serializer 仅为父类对象返回 JSON 并保留子对象相同?

python - 在Python中实现欧拉方法来求解ODE

python - n 的第 N 个斐波那契数等于 10^19?

python - 通过 Cython 调用 inet_pton

django - 是什么导致以下模板错误 'Invalid block tag: ' blocktrans', Expected 'elif' 、 'else' 或 'endif' ?

python - 如何在中心绘制子图并使颜色条与其中一个子图的长度相同?

Django 从 Field 对象获取字段名称

python - 在python中递归加载doctests

python - App Engine python教程错误

python - 用其他值替换零序列