Python rest_framework.exceptions 模块,MethodNotAllowed() 实例源码

我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用rest_framework.exceptions.MethodNotAllowed()

项目:sdining    作者:Lurance    | 项目源码 | 文件源码
def http_method_not_allowed(self, request, *args, **kwargs):
        """
        If `request.method` does not correspond to a handler method,
        determine what kind of exception to raise.
        """
        raise exceptions.MethodNotAllowed(request.method)
项目:sdining    作者:Lurance    | 项目源码 | 文件源码
def get_required_permissions(self, method, model_cls):
        """
        Given a model and an HTTP method, return the list of permission
        codes that the user is required to have.
        """
        kwargs = {
            'app_label': model_cls._meta.app_label,
            'model_name': model_cls._meta.model_name
        }

        if method not in self.perms_map:
            raise exceptions.MethodNotAllowed(method)

        return [perm % kwargs for perm in self.perms_map[method]]
项目:sdining    作者:Lurance    | 项目源码 | 文件源码
def get_required_object_permissions(self, method, model_cls):
        kwargs = {
            'app_label': model_cls._meta.app_label,
            'model_name': model_cls._meta.model_name
        }

        if method not in self.perms_map:
            raise exceptions.MethodNotAllowed(method)

        return [perm % kwargs for perm in self.perms_map[method]]
项目:open-notices    作者:memespring    | 项目源码 | 文件源码
def post(self, request, format='json', *args, **kwargs):
        #Only JSON accepted for edit/create/delete
        if not format == 'json':
            raise MethodNotAllowed('')
        else:
            return super(AlertCreateAPI, self).post(request, format, *args, **kwargs)
项目:open-notices    作者:memespring    | 项目源码 | 文件源码
def post(self, request, format='json', *args, **kwargs):
        #Only JSON accepted for edit/create/delete
        if not format == 'json':
            raise MethodNotAllowed('')
        else:
            return super(NoticeCreateAPI, self).post(request, format, *args, **kwargs)
项目:jianshu-api    作者:strugglingyouth    | 项目源码 | 文件源码
def http_method_not_allowed(self, request, *args, **kwargs):
        """
        If `request.method` does not correspond to a handler method,
        determine what kind of exception to raise.
        """
        raise exceptions.MethodNotAllowed(request.method)
项目:vaultier    作者:Movile    | 项目源码 | 文件源码
def filter_method(self, request):
        """
        Raise 405 whenever http method is patch
        """
        if request.method == "PATCH":
            raise MethodNotAllowed("PATCH")
项目:adhocracy4    作者:liqd    | 项目源码 | 文件源码
def get_rule(self, request, model_cls, method_map):
        template = getattr(method_map, request.method)

        if not template:
            raise exceptions.MethodNotAllowed(request.method)

        return template.format(
            app_label=model_cls._meta.app_label,
            model_name=model_cls._meta.model_name
        )
项目:api-django    作者:lafranceinsoumise    | 项目源码 | 文件源码
def get_required_object_permissions(self, method, model_cls):
        kwargs = {
            'app_label': model_cls._meta.app_label,
            'model_name': model_cls._meta.model_name
        }

        if method not in self.perms_map:
            raise exceptions.MethodNotAllowed(method)

        return [perm % kwargs for perm in self.object_perms_map[method]]
项目:django-daiquiri    作者:aipescience    | 项目源码 | 文件源码
def confirm(self, request, pk=None):
        if not settings.AUTH_WORKFLOW:
            raise MethodNotAllowed('put')

        profile = get_object_or_404(Profile, pk=pk)
        profile.confirm(request)
        return Response(self.get_serializer(profile).data)
项目:django-daiquiri    作者:aipescience    | 项目源码 | 文件源码
def reject(self, request, pk=None):
        if not settings.AUTH_WORKFLOW:
            raise MethodNotAllowed('put')

        profile = get_object_or_404(Profile, pk=pk)
        profile.reject(request)
        return Response(self.get_serializer(profile).data)
项目:django-daiquiri    作者:aipescience    | 项目源码 | 文件源码
def activate(self, request, pk=None):
        if not settings.AUTH_WORKFLOW:
            raise MethodNotAllowed('put')

        profile = get_object_or_404(Profile, pk=pk)
        profile.activate(request)
        return Response(self.get_serializer(profile).data)
项目:SensDB3    作者:aapris    | 项目源码 | 文件源码
def update(self, instance, validated_data):
        request = self.get_request_or_die()
        if not can_edit(request.user, instance, check_api_read_only=False):
            # This branch is only entered when doing a PATCH request (partial
            # update), because datalogger validation is done first.
            raise PermissionDenied(_("Permission to edit Unit denied"))
        elif instance.api_read_only:
            raise MethodNotAllowed(request.method, _("Unit is read only"))
        return super(UnitSerializer, self).update(instance, validated_data)