Python源码示例:django.views.i18n.set_language()
示例1
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
def post(self, request, *args, **kwargs):
if 'nav_menu' in request.session:
del request.session['nav_menu']
return set_language(request)
示例3
def post(self, request, *args, **kwargs):
if 'nav_menu' in request.session:
del request.session['nav_menu']
return set_language(request)
示例4
def post(self, request, *args, **kwargs):
if 'nav_menu' in request.session:
del request.session['nav_menu']
return set_language(request)
示例5
def post(self, request, *args, **kwargs):
if 'nav_menu' in request.session:
del request.session['nav_menu']
return set_language(request)
示例6
def post(self, request, *args, **kwargs):
if 'nav_menu' in request.session:
del request.session['nav_menu']
return set_language(request)
示例7
def post(self, request, *args, **kwargs):
if 'nav_menu' in request.session:
del request.session['nav_menu']
return set_language(request)
示例8
def post(self, request, *args, **kwargs):
if 'nav_menu' in request.session:
del request.session['nav_menu']
return set_language(request)
示例9
def post(self, request, *args, **kwargs):
if 'nav_menu' in request.session:
del request.session['nav_menu']
return set_language(request)
示例10
def post(self, request, *args, **kwargs):
if 'nav_menu' in request.session:
del request.session['nav_menu']
return set_language(request)
示例11
def post(self, request, *args, **kwargs):
if 'nav_menu' in request.session:
del request.session['nav_menu']
return set_language(request)