中国Django管理员不工作

时间:2012-02-29 14:02:29

标签: python django

我正在尝试将Django Admin设置为显示英语。这就是我在settings文件中获得的内容。

gettext = lambda s: s
LANGUAGES = (
    ('zh-tw', gettext('Traditional Chinese'))
)

这是Official docs

的例子

然而,这是我收到的追溯:

环境:

请求方法:GET 请求网址:http://127.0.0.1:8000/admin/

Django Version: 1.3.1
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'myapp']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.middleware.csrf.CsrfResponseMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.locale.LocaleMiddleware')


Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  89.                     response = middleware_method(request)
File "/Library/Python/2.7/site-packages/django/middleware/locale.py" in process_request
  16.         language = translation.get_language_from_request(request)
File "/Library/Python/2.7/site-packages/django/utils/translation/__init__.py" in get_language_from_request
  124.     return _trans.get_language_from_request(request)
File "/Library/Python/2.7/site-packages/django/utils/translation/trans_real.py" in get_language_from_request
  369.     supported = dict(settings.LANGUAGES)

Exception Type: ValueError at /admin/
Exception Value: dictionary update sequence element #0 has length 5; 2 is required

它似乎期望元组的第一个元素有一个2个字符的字符串...但是在文档中它说要使用zh-tw,我真的很茫然......

1 个答案:

答案 0 :(得分:2)

它看起来像一个缺少的逗号:

LANGUAGES = (
     ('zh-tw', gettext('Traditional Chinese')), # <= add a comma here
)