python类HttpResponseGone()的实例源码

views.py 文件源码 项目:ISeeNN 作者: sunshaoyan 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_image(request, id):
    try:
        db_image = DBImage.objects.get(id=id)
        try:
            server = ImageServer.objects.get(id=db_image.server)
            if server.server_name != settings.SERVER_NAME:
                return HttpResponseBadRequest("Image Not On This Server")
        except ImageServer.DoesNotExist:
            return HttpResponseServerError("Image Server Does Not Exist!")
        image_data = open(db_image.path, 'rb').read()
        mime_type = db_image.mime_type
        return HttpResponse(image_data, content_type=mime_type)
    except DBImage.DoesNotExist:
        raise Http404("Image Not Found")
    except IOError:
        return HttpResponseGone("Image Moved")
views.py 文件源码 项目:ISeeNN 作者: sunshaoyan 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_image(request, id):
    try:
        db_image = DBImage.objects.get(id=id)
        mime_type = db_image.mime_type
        try:
            server = ImageServer.objects.get(id=db_image.server)
            ip = server.server_ip
            port = request.META['SERVER_PORT']
            url_ext = reverse('image_server:get_image', args=(str(id) ,))
            remote_url = 'http://' + ip + ':' + str(port) + url_ext
            image_data = urllib.request.urlopen(remote_url).read()
            return HttpResponse(image_data, content_type=mime_type)
        except ImageServer.DoesNotExist:
            return HttpResponseServerError("Image Server Does Not Exist!")
    except DBImage.DoesNotExist:
        raise Http404("Image Not Found")
    except:
        return HttpResponseGone("Image Moved")
views.py 文件源码 项目:ISeeNN 作者: sunshaoyan 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_thumbnail(request, id):
    try:
        db_image = DBImage.objects.get(id=id)
        mime_type = db_image.mime_type
        try:
            server = ImageServer.objects.get(id=db_image.server)
            ip = server.server_ip
            port = request.META['SERVER_PORT']
            url_ext = reverse('image_server:get_thumbnail', args=(str(id) ,))
            remote_url = 'http://' + ip + ':' + str(port) + url_ext
            print(remote_url)
            image_data = urllib.request.urlopen(remote_url).read()
            return HttpResponse(image_data, content_type=mime_type)
        except ImageServer.DoesNotExist:
            return HttpResponseServerError("Image Server Does Not Exist!")
    except DBImage.DoesNotExist:
        raise Http404("Image Not Found")
    except Exception as e:
        print(e)
        return HttpResponseGone("Image Moved")
base.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get(self, request, *args, **kwargs):
        url = self.get_redirect_url(*args, **kwargs)
        if url:
            if self.permanent:
                return http.HttpResponsePermanentRedirect(url)
            else:
                return http.HttpResponseRedirect(url)
        else:
            logger.warning('Gone: %s', request.path,
                        extra={
                            'status_code': 410,
                            'request': request
                        })
            return http.HttpResponseGone()
utils.py 文件源码 项目:django-redirect-urls 作者: pmac 项目源码 文件源码 阅读 54 收藏 0 点赞 0 评论 0
def gone_view(request, *args, **kwargs):
    return HttpResponseGone()
apiv1.py 文件源码 项目:steemprojects.com 作者: noisy 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def apiv1_gone(request):
    return HttpResponseGone(apiv1_gone_msg)
middleware.py 文件源码 项目:tumanov_castleoaks 作者: Roamdev 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def process_response(request, response):
        if response.status_code != 404:
            return response

        full_path = request.get_full_path()

        redirect = None
        try:
            redirect = Redirect.objects.get(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:
                redirect = Redirect.objects.get(old_path=full_path)
            except Redirect.DoesNotExist:
                pass

        if redirect is None:
            return response

        if redirect.new_path == '':
            return http.HttpResponseGone()

        redirect.last_usage = now()
        redirect.save()

        if redirect.permanent:
            return http.HttpResponsePermanentRedirect(redirect.new_path)
        else:
            return http.HttpResponseRedirect(redirect.new_path)
base.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 72 收藏 0 点赞 0 评论 0
def get(self, request, *args, **kwargs):
        url = self.get_redirect_url(*args, **kwargs)
        if url:
            if self.permanent:
                return http.HttpResponsePermanentRedirect(url)
            else:
                return http.HttpResponseRedirect(url)
        else:
            logger.warning(
                'Gone: %s', request.path,
                extra={'status_code': 410, 'request': request}
            )
            return http.HttpResponseGone()
chapter_16_example_15.py 文件源码 项目:two-scoops-of-django-1.11 作者: twoscoops 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def apiv1_gone(request):
    return HttpResponseGone(apiv1_gone_msg)
base.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get(self, request, *args, **kwargs):
        url = self.get_redirect_url(*args, **kwargs)
        if url:
            if self.permanent:
                return http.HttpResponsePermanentRedirect(url)
            else:
                return http.HttpResponseRedirect(url)
        else:
            logger.warning('Gone: %s', request.path,
                        extra={
                            'status_code': 410,
                            'request': request
                        })
            return http.HttpResponseGone()
middleware.py 文件源码 项目:tissuelab 作者: VirtualPlants 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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
base.py 文件源码 项目:django-next-train 作者: bitpixdigital 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def get(self, request, *args, **kwargs):
        url = self.get_redirect_url(*args, **kwargs)
        if url:
            if self.permanent:
                return http.HttpResponsePermanentRedirect(url)
            else:
                return http.HttpResponseRedirect(url)
        else:
            logger.warning('Gone: %s', request.path,
                        extra={
                            'status_code': 410,
                            'request': request
                        })
            return http.HttpResponseGone()
views.py 文件源码 项目:ISeeNN 作者: sunshaoyan 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_thumbnail(request, id):
    try:
        db_image = DBImage.objects.get(id=id)
        thumbnail = db_image.get_thumbnail()
        image_data = thumbnail.file.read()
        mime_type = thumbnail.mime_type
        return HttpResponse(image_data, content_type=mime_type)
    except DBImage.DoesNotExist:
        raise Http404("Image Not Found")
    except IOError:
        return HttpResponseGone("Image Moved")
base.py 文件源码 项目:django-wechat-api 作者: crazy-canux 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get(self, request, *args, **kwargs):
        url = self.get_redirect_url(*args, **kwargs)
        if url:
            if self.permanent:
                return http.HttpResponsePermanentRedirect(url)
            else:
                return http.HttpResponseRedirect(url)
        else:
            logger.warning('Gone: %s', request.path,
                        extra={
                            'status_code': 410,
                            'request': request
                        })
            return http.HttpResponseGone()


问题


面经


文章

微信
公众号

扫码关注公众号