本文整理汇总了Python中django.views.i18n.set_language方法的典型用法代码示例。如果您正苦于以下问题:Python i18n.set_language方法的具体用法?Python i18n.set_language怎么用?Python i18n.set_language使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.views.i18n
的用法示例。
在下文中一共展示了i18n.set_language方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from django.views import i18n [as 别名]
# 或者: from django.views.i18n import set_language [as 别名]
def get(self, request):
"""
In the HTML template we'd like to work with simple links
however the view which actually switches the language needs
to be called via POST so we simulate that here!
If the URL doesn't explicitly specify language then we turn-off
translation mode by switching back to browser preferred language.
"""
browser_lang = self.get_browser_language(request)
post_body = "%s=%s" % (i18n.LANGUAGE_QUERY_PARAMETER,
request.GET.get(i18n.LANGUAGE_QUERY_PARAMETER, browser_lang))
request.META['REQUEST_METHOD'] = 'POST'
request.META['CONTENT_LENGTH'] = len(post_body)
request.META['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
post_request = request.__class__(request.META)
# pylint: disable=protected-access
post_request._post = http.QueryDict(post_body, encoding=post_request._encoding)
return i18n.set_language(post_request)
示例2: post
# 需要导入模块: from django.views import i18n [as 别名]
# 或者: from django.views.i18n import set_language [as 别名]
def post(self, request, *args, **kwargs):
if 'nav_menu' in request.session:
del request.session['nav_menu']
return set_language(request)