Serializers - zamaniamin/python GitHub Wiki
validation
in Views or Serializers?
Is better write In general, it's better to write validation in serializers rather than views.
Serializers are responsible for validating and deserializing input data, whereas views are responsible for handling HTTP requests and returning HTTP responses. By putting validation logic in the serializers, you keep the validation concerns separate from the view concerns. This makes the code more modular and easier to maintain.
In addition, serializers provide more advanced validation features than views, such as field-level validation, cross-field validation, and model-level validation. Serializers can also handle more complex data structures like nested objects and arrays.
However, there may be cases where you need to perform additional validation in the view, such as checking user permissions or performing business logic checks that can't be expressed in the serializer. In those cases, it's okay to perform some validation in the view, but you should try to keep the validation logic to a minimum and delegate as much as possible to the serializer.