django - How to handle user registration over django_rest_framework based API -
how handle user registration on , api using django_rest_framework? specifically, how set password field in userserializer
class newuserserializer(serializer.serializers): first_name = serializers.charfield(required=true, max_length=30) last_name = serializers.charfield(required=true, max_length=30) username = serlializers.charfield(required=true, max_length=30) email = serializers.emailfield(required=true) password = ??? def restore_object(self, attrs, instance=none): if instance: instance.username = attrs.get('username', instance.username) instance.first_name = attrs.get('first_name', instance.first_name) instance.last_name = attrs.get('last_name', instance.last_name) instance.email = attrs.get('email', instance.email) # instance.password field necessary? instance.password = attrs.get('password', instance.password) else: return user(**attrs)
you can use charfield password. , dont need restore_object @ all. can this, define fields , :
serializer = newuserserializer(data=request.data) if serializer.is_valid(): email = serializer.object["email"] password = serializer.object["password"] # stuff want here
Comments
Post a Comment