根据不同的用户显示不同的语言


class LocaleMiddleware(object):

def get_language_forr_user(self,request):
if request.user.is_authenticated():
try:
account = Account.objects.get(user=request.user)
return account.language
except:
pass
return translation.get_language_from_request(request)



def process_request(self,request):
translation.active(self.get_language_for_user(request))
request.LANGUAGE_CODE = translation.get_language()

def process_response(self,request,response):
patch_vary_headers(response,('Accept-Language',))
reposnse['Content-Language'] = translation.get_language()
translation.deactivate()
return response

你可能感兴趣的:(python)