from django.utils import translationdef home_index(request):return redirect('home', lang='zh-hans')def home(request):ua = request.META.get('HTTP_USER_AGENT')accept = request.META.get('HTTP_ACCEPT')# 从请求META中获取accept_lang = request.META.get('HTTP_ACCEPT_LANGUAGE')# 从请求中获取lang_a = translation.get_language_from_request(request)# 从路径中获取lang_path = translation.get_language_from_path(request.path)# 激活语言translation.activate(lang_a)return render(request, 'home.html')
