我有一个多语言网站(it,en,ru),它使用django-cms和一些挂在不同页面上的应用程序。我的问题是内容总是以意大利语提供,即使我访问带有'/ en /'或'/ ru /'作为前缀的页面。 在我的基本模板(base.html)上,我有一个{{lang}}模板变量,允许我检索当前的页面语言,它工作正常......直到今天。现在如果我访问 wwww.myhomepage / en (或 / ru ),'lang'的值是总是'它'。
这些是我的语言设置(cms而不是cms)以及与语言相关的其他设置:
LANGUAGE_CODE = 'it'
DEFAULT_LANGUAGE = 0
LANGUAGES = (
('it', gettext(u'Italiano')),
('en', gettext(u'English')),
('ru', gettext(u'Russian')), )
CMS_LANGUAGES = (
('it', ugettext('Italian')),
('en', ugettext('English')),
('ru', ugettext('Russian')),
)
LOCALE_PATHS = (os.path.join(PROJECT_PATH, 'locale'))
CMS_LANGUAGE_CONF = {
'it': ['en'],
'ru': ['en'],
}
CMS_HIDE_UNTRANSLATED = False
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'cms.middleware.multilingual.MultilingualURLMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'cms.middleware.multilingual.MultilingualURLMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'cms.middleware.multilingual.MultilingualURLMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware'
)
有什么帮助吗? 感谢名单
答案 0 :(得分:0)
您的设置中有多个重复的中间件。他们应该看起来像这样:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'cms.middleware.multilingual.MultilingualURLMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
)
另外,您是否也可以提供CONTEXT_PROCESSOR
设置?
然后,我假设您使用的是Django-cms< = 2.3.5。这是正确的吗?有一个2.4测试版正在摆脱MultilingualMiddleware,如果你可以尝试它是否适合你(即使它仍然是一个测试版)。