Home > Mobile >  AttributeError: module 'rest_framework.serializers' has no attribute 'validationError
AttributeError: module 'rest_framework.serializers' has no attribute 'validationError

Time:01-03

def validate_name(self,value):

    qs=contact.objects.filter(name=value)
    if qs.exists():
        raise serializers.validationError(f"{value} is already in contact name")
    return value

error:

in validate_name raise serializers.validationError(f"{value} is already in contact name")
AttributeError: module 'rest_framework.serializers' has no attribute 'validationError'

validate the name is already exists

CodePudding user response:

The ValidationError is a class, so it should begin with capitals.

serializers.ValidationError("Error text")

CodePudding user response:

https://www.django-rest-framework.org/api-guide/exceptions/ from original docs

raise serializers.ValidationError({'field_name': 'your message'})

you can import from rest framework like this

from rest_framework.serializers import ValidationError
  • Related