如何更改Django管理语言?

时间:2022-04-08 20:14:23

I have a django 1.6 site with i18n working. I can change the frontend language with a select box in the top of the template, but I don't know if there is a django app or trick to change the admin language, because it seems to store somewhere in session variable, and it keeps the first language I have used in the frontend.

我有一个运行i18n的django 1.6网站。我可以使用模板顶部的选择框更改前端语言,但我不知道是否有django应用程序或技巧来更改管理语言,因为它似乎存储在会话变量中的某个位置,并且它保持我在前端使用的第一种语言。

2 个解决方案

#1


10  

You can create /en/admin, /fr/admin/ and so on using i18n_patterns:

您可以使用i18n_patterns创建/ en / admin,/ fr / admin /等等:

urlpatterns += i18n_patterns(
    url(r'^admin/', include(admin.site.urls)),
)

(For Django <= 1.7, you must specify a prefix, use i18n_patterns('', ... ))

(对于Django <= 1.7,你必须指定一个前缀,使用i18n_patterns('',...))

#2


10  

In your settings.py just add 'django.middleware.locale.LocaleMiddleware' to your MIDDLEWARE_CLASSES setting, making sure it appears after 'django.contrib.sessions.middleware.SessionMiddleware'.

在你的settings.py中,只需将'django.middleware.locale.LocaleMiddleware'添加到MIDDLEWARE_CLASSES设置中,确保它出现在'django.contrib.sessions.middleware.SessionMiddleware'之后。

#1


10  

You can create /en/admin, /fr/admin/ and so on using i18n_patterns:

您可以使用i18n_patterns创建/ en / admin,/ fr / admin /等等:

urlpatterns += i18n_patterns(
    url(r'^admin/', include(admin.site.urls)),
)

(For Django <= 1.7, you must specify a prefix, use i18n_patterns('', ... ))

(对于Django <= 1.7,你必须指定一个前缀,使用i18n_patterns('',...))

#2


10  

In your settings.py just add 'django.middleware.locale.LocaleMiddleware' to your MIDDLEWARE_CLASSES setting, making sure it appears after 'django.contrib.sessions.middleware.SessionMiddleware'.

在你的settings.py中,只需将'django.middleware.locale.LocaleMiddleware'添加到MIDDLEWARE_CLASSES设置中,确保它出现在'django.contrib.sessions.middleware.SessionMiddleware'之后。