Django rest framework email validation -


i want validate email id if exists in user model before registration

this serializer validation

class registrationserializer(serializers.serializer):     username = serializers.charfield(max_length=100)     email = serializers.emailfield()     password = serializers.charfield(max_length=100)      def validate_email(self,attrs):             email=attrs['email']             print email             if email:                     emailset = q(email__icontains=email)                     emailres = user.objects.filter(emailset)                     if emailres:                             msg = _('the email address taken')                             raise serializers.validationerror(msg)                     else:                             return attars 

it throwing error "typeerror:string indices must integers"

 email=attrs['email'] 

typeerror: string indices must integers

i guess have upgraded or using drf 3.x, there no more attrs dict value instead. see field-level-validation

more on there uniquevalidator. think can do:

class registrationserializer(serializers.serializer):     #...     email = serializers.emailfield(validators=[uniquevalidator(queryset=user.objects.all())]) 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -