How to use django.views.i18n.set_language() function?

不羁岁月 提交于 2019-12-04 12:45:29

With the code you are using, you don't need to write your own views. The form will make a POST request to /i18n/setlang/, with the language code and (optional) the redirect-to (next) page as parameters.

The django view does the following (from the django documentation)

Django looks for a next parameter in the POST data. - If that doesn't exist, or is empty, Django tries the URL in the Referrer header. - If that's empty -- say, if a user's browser suppresses that header -- then the user will be - redirected to / (the site root) as a fallback.

So in essence, the user will be redirected after submitting the form, and the django view will set the language for that user according to what was submitted.

Hope this helps,

Hoff

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!