当前位置: 首页>>代码示例>>Python>>正文


Python Redirect.DoesNotExist方法代码示例

本文整理汇总了Python中django.contrib.redirects.models.Redirect.DoesNotExist方法的典型用法代码示例。如果您正苦于以下问题:Python Redirect.DoesNotExist方法的具体用法?Python Redirect.DoesNotExist怎么用?Python Redirect.DoesNotExist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.redirects.models.Redirect的用法示例。


在下文中一共展示了Redirect.DoesNotExist方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_response

# 需要导入模块: from django.contrib.redirects.models import Redirect [as 别名]
# 或者: from django.contrib.redirects.models.Redirect import DoesNotExist [as 别名]
def process_response(self, request, response):
        # No need to check for a redirect for non-404 responses.
        if response.status_code != 404:
            return response

        full_path = request.get_full_path()
        current_site = get_current_site(request)

        r = None
        try:
            r = Redirect.objects.get(site=current_site, old_path=full_path)
        except Redirect.DoesNotExist:
            pass
        if r is None and settings.APPEND_SLASH and not request.path.endswith('/'):
            try:
                r = Redirect.objects.get(
                    site=current_site,
                    old_path=request.get_full_path(force_append_slash=True),
                )
            except Redirect.DoesNotExist:
                pass
        if r is not None:
            if r.new_path == '':
                return self.response_gone_class()
            return self.response_redirect_class(r.new_path)

        # No redirect was found. Return the response.
        return response 
开发者ID:ComputerSocietyUNB,项目名称:CodingDojo,代码行数:30,代码来源:middleware.py

示例2: process_response

# 需要导入模块: from django.contrib.redirects.models import Redirect [as 别名]
# 或者: from django.contrib.redirects.models.Redirect import DoesNotExist [as 别名]
def process_response(self, request, response):
        # No need to check for a redirect for non-404 responses.
        if response.status_code != 404:
            return response

        full_path = request.get_full_path()
        current_site = get_current_site(request)

        r = None
        try:
            r = Redirect.objects.get(site=current_site, old_path=full_path)
        except Redirect.DoesNotExist:
            pass
        if settings.APPEND_SLASH and not request.path.endswith('/'):
            # Try appending a trailing slash.
            path_len = len(request.path)
            full_path = full_path[:path_len] + '/' + full_path[path_len:]
            try:
                r = Redirect.objects.get(site=current_site, old_path=full_path)
            except Redirect.DoesNotExist:
                pass
        if r is not None:
            if r.new_path == '':
                return self.response_gone_class()
            return self.response_redirect_class(r.new_path)

        # No redirect was found. Return the response.
        return response 
开发者ID:0daybug,项目名称:DjangoBlog,代码行数:30,代码来源:middleware.py

示例3: process_response

# 需要导入模块: from django.contrib.redirects.models import Redirect [as 别名]
# 或者: from django.contrib.redirects.models.Redirect import DoesNotExist [as 别名]
def process_response(self, request, response):
        if response.status_code != 404:
            return response # No need to check for a redirect for non-404 responses.

        full_path = request.get_full_path()
        current_site = get_current_site(request)

        r = None
        try:
            r = Redirect.objects.get(site=current_site, old_path=full_path)
        except Redirect.DoesNotExist:
            pass
        if settings.APPEND_SLASH and not request.path.endswith('/'):
            # Try appending a trailing slash.
            path_len = len(request.path)
            full_path = full_path[:path_len] + '/' + full_path[path_len:]
            try:
                r = Redirect.objects.get(site=current_site, old_path=full_path)
            except Redirect.DoesNotExist:
                pass
        if r is not None:
            if r.new_path == '':
                return http.HttpResponseGone()
            return http.HttpResponsePermanentRedirect(r.new_path)

        # No redirect was found. Return the response.
        return response 
开发者ID:VirtualPlants,项目名称:tissuelab,代码行数:29,代码来源:middleware.py


注:本文中的django.contrib.redirects.models.Redirect.DoesNotExist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。