areas.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:aiohttp-three-template 作者: RobertoPrevato 项目源码 文件源码
def _get_culture_for_request(self, request):
        """
        Gets the culture to use for a given request.
        """
        if "GET" == request.method:
            culture = request.match_info.get("culture")
            if culture:
                if not self._is_supported_culture(culture):
                    # the given culture is not supported; the user could have changed a url by hand
                    # raise an exception to redirect to a proper url
                    raise InvalidCultureException()
                return culture

        user = request.user
        if user and not user.anonymous and self._is_supported_culture(user.culture):
            return user.culture

        if "POST" == request.method:
            # check custom headers
            culture_header = request.headers.get("X-Request-Culture")
            if self._is_supported_culture(culture_header):
                return culture_header

        culture_cookie = request.cookies.get("culture")
        if self._is_supported_culture(culture_cookie):
            return culture_cookie
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号