Django rest framework - ValidationError raised in models' save method. How to pass error to http response

I'm using the django rest framework, with a ModelViewset:

I'm using the django rest framework, with a ModelViewset:

class FooViewset(viewsets.ModelViewSet):
    serializer_class = FooSerializer
    queryset = Foo.objects.all()

and a ModelSerializer:

class FooSerializer(serializers.ModelSerializer):
class Meta:
    model = Foo
    fields = [
        "id",
        "bar",
        "baz",
    ]

I also have the model's save method:

class Foo(models.Model):
...
def save(self):
if condition:
raise ValidationError("Illegal parameters")
return super().save(*args, **kwargs)

When this validation error is triggered, drf, sends a 500 response to the frontend, with no text. How do I get it to instead give a 'bad request' response, with the text in the ValidationError (Illegal parameter)?

Python Django Tutorial | Django Course

Python Django Tutorial | Django Course

🔥Intellipaat Django course: https://intellipaat.com/python-django-training/ 👉This Python Django tutorial will help you learn what is django web development &...

This Python Django tutorial will help you learn what is django web development & application, what is django and introduction to django framework, how to install django and start programming, how to create a django project and how to build django app. There is a short django project as well to master this python django framework.

Why should you watch this Django tutorial?

You can learn Django much faster than any other programming language and this Django tutorial helps you do just that. Our Django tutorial has been created with extensive inputs from the industry so that you can learn Django and apply it for real world scenarios.

Django

Well i used django ... i want to know after completing all the coding stuff, can i make all the codes online ?

Well i used django ... i want to know after completing all the coding stuff, can i make all the codes online ?

as Django give you a local host, i have a .com domain but can i integrate the codes to it so it works ?