python类is_valid_path()的实例源码

common.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def should_redirect_with_slash(self, request):
        """
        Return True if settings.APPEND_SLASH is True and appending a slash to
        the request path turns an invalid path into a valid one.
        """
        if settings.APPEND_SLASH and not request.get_full_path().endswith('/'):
            urlconf = getattr(request, 'urlconf', None)
            return (
                not urlresolvers.is_valid_path(request.path_info, urlconf)
                and urlresolvers.is_valid_path('%s/' % request.path_info, urlconf)
            )
        return False
common.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def should_redirect_with_slash(self, request):
        """
        Return True if settings.APPEND_SLASH is True and appending a slash to
        the request path turns an invalid path into a valid one.
        """
        if settings.APPEND_SLASH and not request.get_full_path().endswith('/'):
            urlconf = getattr(request, 'urlconf', None)
            return (
                not urlresolvers.is_valid_path(request.path_info, urlconf)
                and urlresolvers.is_valid_path('%s/' % request.path_info, urlconf)
            )
        return False
common.py 文件源码 项目:django-next-train 作者: bitpixdigital 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def should_redirect_with_slash(self, request):
        """
        Return True if settings.APPEND_SLASH is True and appending a slash to
        the request path turns an invalid path into a valid one.
        """
        if settings.APPEND_SLASH and not request.get_full_path().endswith('/'):
            urlconf = getattr(request, 'urlconf', None)
            return (
                not urlresolvers.is_valid_path(request.path_info, urlconf)
                and urlresolvers.is_valid_path('%s/' % request.path_info, urlconf)
            )
        return False
middleware.py 文件源码 项目:tumanov_castleoaks 作者: Roamdev 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def process_request(request):
        # ????????? ?????? ????????????? ????? GET-????????
        if request.GET.get(options.MULTILANGUAGE_GET_PARAM):
            request.disable_autoredirect = True

            # ?????????, ??? ?? ??????? ????? ???? ????? ????????,
            # ?????, ?????????? ?? MULTILANGUAGE_FALLBACK_URL
            urlconf = getattr(request, 'urlconf', None)
            if not is_valid_path(request.path_info, urlconf):
                return redirect(options.MULTILANGUAGE_FALLBACK_URL)

            return

        # ????????? ?????? ????????????? ????? ????
        if request.COOKIES.get(options.MULTILANGUAGE_COOKIE_KEY, None):
            return

        # ????????? ?????? ????????????? ??? ???????????? User-Agent
        ua_string = request.META.get('HTTP_USER_AGENT', '').lower()
        for pattern in options.ROBOTS_UA:
            if pattern in ua_string:
                return

        # ????????? ?????????? ? IP
        ip = get_client_ip(request)
        ip_info = info(ip, detailed=True)
        if not ip_info:
            request.disable_autoredirect = True
            return

        # ??????????? ???? ?????, ?? ??????? ????? ???????????
        current_code = settings.LANGUAGE_CODE
        redirect_code = current_code
        try:
            ip_iso = ip_info.get('country').get('iso')
        except AttributeError:
            pass
        else:
            for code, opts in options.MULTILANGUAGE_SITES.items():
                iso = opts.get('iso')
                if iso and ip_iso in iso:
                    redirect_code = code
                    break

        if current_code != redirect_code:
            request.disable_autoredirect = True
            language = options.MULTILANGUAGE_SITES.get(redirect_code)
            if language:
                redirect_url = noredirect_url(language['url'], forced_path=request.path)
                return redirect(redirect_url)


问题


面经


文章

微信
公众号

扫码关注公众号