Python django.core.urlresolvers 模块,is_valid_path() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用django.core.urlresolvers.is_valid_path()

项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
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
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
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
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
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
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
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)