How can I change Django admin language?

2019-04-24 08:48发布

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.

2条回答
姐就是有狂的资本
2楼-- · 2019-04-24 09:01

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'.

查看更多
3楼-- · 2019-04-24 09:15

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

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

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

查看更多
登录 后发表回答