How to explicitly set django_language in django session

前端 未结 3 1150
有刺的猬
有刺的猬 2020-12-23 22:27

How to explicitly set django_language in Django session?

Thanks a lot...

3条回答
  •  余生分开走
    2020-12-23 23:12

    Consider using django.views.i18n.set_language(). Activate this view by adding the following line to your URLconf:

    # This example makes the view available at /i18n/setlang/
    url(r'^i18n/', include('django.conf.urls.i18n')),
    

    As a convenience, Django comes with a view, django.views.i18n.set_language(), that sets a user’s language preference and redirects to a given URL or, by default, back to the previous page.

    The view expects to be called via the POST method, with a language parameter set in request. If session support is enabled, the view saves the language choice in the user’s session. Otherwise, it saves the language choice in a cookie that is by default named django_language. (The name can be changed through the LANGUAGE_COOKIE_NAME setting.)

提交回复
热议问题