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


Python response.Http404方法代码示例

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


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

示例1: finish_reservation

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def finish_reservation(request):
    if not hasattr(request, 'reservation'):
        raise Http404(_("No reservation object started"))

    if request.method == "GET":
        response = render(
            request,
            'djreservation/reservation_confirm.html',
            {"reservation": request.reservation})
    elif request.method == "POST":
        reservation = request.reservation
        reservation.status = reservation.REQUESTED
        reservation.save()
        request.reservation = None
        send_reservation_email(reservation, request.user)
        response = render(
            request, 'djreservation/reservation_finished.html')
        response.set_cookie("reservation", "0")
        messages.success(request, _('Reservation finised'))
    return response 
开发者ID:luisza,项目名称:djreservation,代码行数:22,代码来源:views.py

示例2: update_reservation_by_token

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def update_reservation_by_token(request, pk, token, status):
    token_reservation = get_object_or_404(ReservationToken, reservation=pk,
                                          token=token)
    status_available = list(dict(Reservation.STATUS).keys())
    if int(status) not in status_available:
        raise Http404()

    reservation = token_reservation.reservation

    if int(status) == Reservation.ACCEPTED:
        reservation.product_set.all().update(borrowed=True)
    reservation.status = status
    reservation.save()
    token_reservation.delete()
    messages.success(request, _('Reservation updated successful'))
    return redirect("/") 
开发者ID:luisza,项目名称:djreservation,代码行数:18,代码来源:views.py

示例3: create_result_response

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def create_result_response(self, service, result, service_path):
        for nested in service_path:
            result = result.get(nested, None)
            if result is None:
                break

        if result is None:
            raise Http404()

        if result in (True, False):
            status_code = 200 if result else _get_err_status_code()
            return HttpResponse(str(result).lower(), status=status_code)
        elif isinstance(result, six.string_types) or isinstance(result, bytes):
            return HttpResponse(result)
        else:
            # Django requires safe=False for non-dict values.
            return JsonResponse(result, safe=False) 
开发者ID:mvantellingen,项目名称:django-healthchecks,代码行数:19,代码来源:views.py

示例4: handle_exception

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def handle_exception(self, exc: Exception, action: str, request_id):
        """
        Handle any exception that occurs, by sending an appropriate message
        """
        if isinstance(exc, APIException):
            await self.reply(
                action=action,
                errors=self._format_errors(exc.detail),
                status=exc.status_code,
                request_id=request_id,
            )
        elif exc == Http404 or isinstance(exc, Http404):
            await self.reply(
                action=action,
                errors=self._format_errors("Not found"),
                status=404,
                request_id=request_id,
            )
        else:
            raise exc 
开发者ID:hishnash,项目名称:djangochannelsrestframework,代码行数:22,代码来源:consumers.py

示例5: retrieve_impl

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def retrieve_impl(self, request, name):
        """Retrieves the details for metrics and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param name: the name of the metrics detail to retrieve.
        :type name: string
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """
        try:
            metrics_type = registry.get_metrics_type(name, include_choices=True)
            serializer_class = registry.get_serializer(name) or MetricsTypeDetailsSerializer
        except MetricsTypeError:
            raise Http404

        return Response(serializer_class(metrics_type).data) 
开发者ID:ngageoint,项目名称:scale,代码行数:19,代码来源:views.py

示例6: get_v6

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def get_v6(self, request, dataset_id):
        """Retrieves the details for a dataset version and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param dataset_id: The dataset id
        :type dataset_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            dataset = DataSet.objects.get_details_v6(dataset_id)
        except DataSet.DoesNotExist:
            raise Http404

        serializer = self.get_serializer(dataset)
        return Response(serializer.data) 
开发者ID:ngageoint,项目名称:scale,代码行数:20,代码来源:views.py

示例7: list_v6

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def list_v6(self, request, dataset_id):
        """Retrieves the members for a dataset version and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param dataset_id: The dataset id
        :type dataset_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            dataset = DataSet.objects.get(pk=dataset_id)
        except DataSet.DoesNotExist:
            raise Http404

        dsm = DataSetMember.objects.get_dataset_members(dataset=dataset)

        page = self.paginate_queryset(dsm)
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data) 
开发者ID:ngageoint,项目名称:scale,代码行数:23,代码来源:views.py

示例8: retrieve

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def retrieve(self, request, ingest_id=None, file_name=None):
        """Determine api version and call specific method

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param ingest_id: The id of the ingest
        :type ingest_id: int encoded as a str
        :param file_name: The name of the ingest
        :type file_name: string
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6' or request.version == 'v7':
            return self.retrieve_v6(request, ingest_id)

        raise Http404() 
开发者ID:ngageoint,项目名称:scale,代码行数:19,代码来源:views.py

示例9: post

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def post(self, request, scan_id=None):
        """Launches a scan to ingest from an existing scan model instance

        :param request: the HTTP POST request
        :type request: :class:`rest_framework.request.Request`
        :param scan_id: ID for Scan record to pull configuration from
        :type scan_id: int
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._post_v6(request, scan_id)
        elif request.version == 'v7':
            return self._post_v6(request, scan_id)

        raise Http404() 
开发者ID:ngageoint,项目名称:scale,代码行数:19,代码来源:views.py

示例10: _post_v6

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def _post_v6(self, request, scan_id=None):
        """Launches a scan to ingest from an existing scan model instance

        :param request: the HTTP POST request
        :type request: :class:`rest_framework.request.Request`
        :param scan_id: ID for Scan record to pull configuration from
        :type scan_id: int
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        ingest = rest_util.parse_bool(request, 'ingest', default_value=False)

        try:
            scan = Scan.objects.queue_scan(scan_id, dry_run=not ingest)
        except Scan.DoesNotExist:
            raise Http404

        serializer = self.get_serializer(scan)
        return Response(serializer.data, status=status.HTTP_201_CREATED) 
开发者ID:ngageoint,项目名称:scale,代码行数:22,代码来源:views.py

示例11: get

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def get(self, request, scan_id):
        """Retrieves the details for a Scan process and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param scan_id: The ID of the Scan process
        :type scan_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._get_v6(request, scan_id)
        elif request.version == 'v7':
            return self._get_v6(request, scan_id)

        raise Http404() 
开发者ID:ngageoint,项目名称:scale,代码行数:19,代码来源:views.py

示例12: _get_v6

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def _get_v6(self, request, scan_id):
        """Retrieves the details for a Scan process and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param scan_id: The ID of the Scan process
        :type scan_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            scan = Scan.objects.get_details(scan_id)
        except Scan.DoesNotExist:
            raise Http404

        serializer = self.get_serializer(scan)
        return Response(serializer.data) 
开发者ID:ngageoint,项目名称:scale,代码行数:20,代码来源:views.py

示例13: patch

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def patch(self, request, scan_id):
        """Edits an existing Scan process and returns the updated details

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param scan_id: The ID of the Scan process
        :type scan_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._patch_v6(request, scan_id)
        elif request.version == 'v7':
            return self._patch_v6(request, scan_id)

        raise Http404() 
开发者ID:ngageoint,项目名称:scale,代码行数:19,代码来源:views.py

示例14: get_impl

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def get_impl(self, request, strike_id):
        """Retrieves the details for a Strike process and return them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param strike_id: The ID of the Strike process
        :type strike_id: int encoded as a str
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        try:
            is_staff = False
            if request.user:
                is_staff = request.user.is_staff
            strike = Strike.objects.get_details(strike_id, is_staff)
        except Strike.DoesNotExist:
            raise Http404

        serializer = self.get_serializer(strike)
        return Response(serializer.data) 
开发者ID:ngageoint,项目名称:scale,代码行数:23,代码来源:views.py

示例15: retrieve

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import Http404 [as 别名]
def retrieve(self, request, batch_id):
        """Retrieves the details for a batch and returns them in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :param batch_id: The batch ID
        :type batch_id: int
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        if request.version == 'v6':
            return self._retrieve_v6(batch_id)
        elif request.version == 'v7':
            return self._retrieve_v6(batch_id)

        raise Http404() 
开发者ID:ngageoint,项目名称:scale,代码行数:19,代码来源:views.py


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