安装django-cms报错,ImproperlyConfigured: LANGUAGE_CODE "en-us" must have a matching entry in LANGUAG解决办法

时间:2022-06-10 23:35:05
ImproperlyConfigured: LANGUAGE_CODE "en-us" must have a matching entry in LANGUAGES

[17/Apr/2014 17:48:10] "GET /zh-cn/ HTTP/1.1" 500 59


这个issue在github上提交过,传送门 https://github.com/divio/django-cms/issues/2179




回答是这样的:

If your LANGUAGE_CODE is 'en-us' and in your LANGUAGES you have: 'en' and 'de' then django actually supports 3 languages: 'en-us', 'en' and 'de'. The problem is that 'en-us' is not the same as 'en' and it is possible that request.LANGUAGE_CODE becomes 'en-us' if you don't have the language accept headers set. We have 2 possible solutions: Either we add LANGUAGE_CODE to CMS_LANGUAGES as well... and then you can create pages in 'en-us' and 'en' or we enforce that LANGUAGE_CODE is in LANGUAGES. To be honest i think the django docs in this regard should be updated as most people will not understand what is going on in the back and only encounter 500 after they go live and they receive a request without a accept language header and have a new language to deal with for the first time.

PS. over the years i had soooo many bug reports because of this behavior that i finally decided to enforce the LANGUAGE_CODE in LANGUAGES as it makes absolutely sense in a i18n environment.


有两种解决方案,我用的后一种:在LANGUAGES里把 ('en', gettext_noop('English')) 改成 ('en-us', gettext_noop('English')),


LANGUAGES = (
    ('en-us', gettext_noop('English')),
    ('zh-cn', gettext_noop('Simplified Chinese')),
    ('zh-tw', gettext_noop('Traditional Chinese')),
)