[Answered ]-Filter Backends Django Rest Framework List API View

1πŸ‘

βœ…

In both Django and in Django Rest Framework these type of things are dealt with by raising Exceptions:

from rest_framework.exceptions import APIException


class BadParameter(APIException):
    status_code = 400
    default_detail = 'The parameter x is wrong or empty'
    default_code = 'bad_param'

# ...

class PlantListByClientView(generics.ListAPIView):
    # ...
    def list(self, request, *args, **kwargs):
        # ...
        if bad_param:
            raise BadParameter()

Some parts of the framework will raise exceptions for you, like, for example, serializes rising ValidationError when validation fails.

πŸ‘€Igonato

Leave a comment