MultiValueDictKeyError Django CMS - 在QueryDict中找不到密钥“语言”

时间:2013-07-29 18:44:33

标签: django django-cms

由于帖子中没有“语言”,我的Django CMS网站突然无法发布网页或添加插件。我以前从未见过这个问题而且我不确定如何修复它。回溯在下面。

Django 1.4.5版

Django CMS版本2.4.2

"Key 'language' not found in <QueryDict: {u'placeholder': [u'1434'], u'plugin_type': [u'TextPlugin']}>"

Request Method: POST
Request URL:  http://domain.com/admin/cms/page/495/add-plugin/
Django Version: 1.4.5
Exception Type: MultiValueDictKeyError
Exception Value:  
"Key 'language' not found in <QueryDict: {u'placeholder': [u'1434'], u'plugin_type': [u'TextPlugin']}>"
Exception Location: /var/www/.virtualenvs/domain.com/lib/python2.6/site-packages/django/utils/datastructures.py in __getitem__, line 258
Python Executable:  /var/www/.virtualenvs/domain.com/bin/python
Python Version: 2.6.6
Python Path:  
['/var/www/domain.com/app',
 '/var/www/.virtualenvs/domain.com/bin',
 '/var/www/.virtualenvs/domain.com/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg',
 '/var/www/.virtualenvs/domain.com/lib/python2.6/site-packages/pip-1.3.1-py2.6.egg',
 '/var/www/.virtualenvs/domain.com/src/django-admin-bootstrapped',
 '/var/www/.virtualenvs/domain.com/src/johnny-panel',
 '/var/www/.virtualenvs/domain.com/lib64/python26.zip',
 '/var/www/.virtualenvs/domain.com/lib64/python2.6',
 '/var/www/.virtualenvs/domain.com/lib64/python2.6/plat-linux2',
 '/var/www/.virtualenvs/domain.com/lib64/python2.6/lib-tk',
 '/var/www/.virtualenvs/domain.com/lib64/python2.6/lib-old',
 '/var/www/.virtualenvs/domain.com/lib64/python2.6/lib-dynload',
 '/usr/lib64/python2.6',
 '/usr/lib/python2.6',
 '/var/www/.virtualenvs/domain.com/lib/python2.6/site-packages']


 /var/www/.virtualenvs/domain.com/lib/python2.6/site-packages/cms/admin/pageadmin.py in add_plugin
            language = request.POST['language'] or get_language_from_request(request)
Local Vars

Variable  Value
parent  
None
self  
<cms.admin.pageadmin.PageAdmin object at 0x3b58710>
request 
"<WSGIRequest\npath:/admin/cms/page/495/add-plugin/,
GET:<QueryDict: {}>,
POST:<QueryDict: {u'placeholder': [u'1434'], u'plugin_type': [u'TextPlugin']}>,
 META:{'CONTENT_LENGTH': '39',
 'CONTENT_TYPE': 'application/x-www-form-urlencoded',
 'CSRF_COOKIE': 'YmXTWNblNRZix37nd5xINn6Eq0VciynN',
 'HTTP_ACCEPT': 'text/html, */*',
 'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch',
 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8',
 'HTTP_CONNECTION': 'close',
 'HTTP_COOKIE': 'djangocms_nodes_open=page_502; CMS_toolbar-collapsed=false;,
 'HTTP_HOST': 'domain.com',
 'HTTP_ORIGIN': 'http://domain.com',
 'HTTP_REFERER': 'http://domain.com/admin/cms/page/495/',
 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.32 Safari/537.36',
 'HTTP_X_CSRFTOKEN': 'YmXTWNblNRZix37nd5xINn6Eq0VciynN',
 'HTTP_X_FORWARDED_FOR': '64.21.121.50',
 'HTTP_X_REAL_IP': '64.21.121.50',
 'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
 'PATH_INFO': u'/admin/cms/page/495/add-plugin/',
 'QUERY_STRING': '',
 'RAW_URI': '/admin/cms/page/495/add-plugin/',
 'REMOTE_ADDR': '64.21.121.50',
 'REMOTE_PORT': '80',
 'REQUEST_METHOD': 'POST',
 'SCRIPT_NAME': u'',
 'SERVER_NAME': 'domain.com',
 'SERVER_PORT': '80',
 'SERVER_PROTOCOL': 'HTTP/1.0',
 'SERVER_SOFTWARE': 'gunicorn/0.17.2',
 'gunicorn.socket': <socket._socketobject object at 0x210b980>,
 'wsgi.errors': <gunicorn.glogging.LazyWriter object at 0x1b068d0>,
 'wsgi.file_wrapper': <class gunicorn.http.wsgi.FileWrapper at 0x1bd3ef0>,
 'wsgi.input': <gunicorn.http.body.Body object at 0x21346d0>,
 'wsgi.multiprocess': True,
 'wsgi.multithread': False,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 0)}>"
parent_id 
None
placeholder_id  
u'1434'
placeholder 
<Placeholder: main-content>
page  
<cms.models.pagemodel.Page object at 0x4192210>
plugin_type 
u'TextPlugin'
/var/www/.virtualenvs/domain.com/lib/python2.6/site-packages/django/utils/datastructures.py in __getitem__
            raise MultiValueDictKeyError("Key %r not found in %r" % (key, self))
Local Vars

Variable  Value
self  
<QueryDict: {u'placeholder': [u'1434'], u'plugin_type': [u'TextPlugin']}>
key 
'language'

更新

直接来自python shell的语言设置:

settings.LANGUAGES    
[('en', 'English')]

settings.LANGUAGE_CODE    
'en'

settings.LANGUAGE_COOKIE_NAME    
'django_language'    

settings.DEFAULT_LANGUAGE    
0

settings.USE_I18N    
False

settings.USE_L10N    
False

1 个答案:

答案 0 :(得分:1)

当POST数据中不存在'languages'时,django cms存在抛出错误的问题; MultiValueDictKeyError错误。

在撰写本文时,有一个来自@blackrobot的修复请求。 https://github.com/divio/django-cms/pull/2151

如果您需要在将修复程序集成到主分支并释放之前进行修复,则可以进行此分析或编辑本地副本。编辑

的第1130行
cms/admin/pageadmin.py

成为

language = request.POST.get('language') or get_language_from_request(request)