7

I am done with the registration as you can see. Now I want to send email verification so users can confirm. So once a user register, he/she gets a mail for confirmation.

how do I send email verification using "ListCreateAPIView"?

Do I need a third party package?

Can someone help me out? Thanks

Here is my view

class UserList(generics.ListCreateAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer


class UserDetail(generics.RetrieveAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer

My serializer.py

class UserSerializer(serializers.ModelSerializer):
    email = serializers.EmailField(required=True, validators=[UniqueValidator(queryset=User.objects.all())])
    username = serializers.CharField(required=True, validators=[UniqueValidator(queryset=User.objects.all())])
    password = serializers.CharField(min_length=8, style={'input_type': 'password', 'placeholder': 'Password'})


    def create(self, validated_data):
        user = User.objects.create_user(validated_data['username'], validated_data['email'], validated_data['password'])
        return user

    class Meta:
        model = User
        fields = ('id', 'username', 'email', 'password')

2 Answers 2

1
from django.core.mail import send_mail
class UserList(generics.ListCreateAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer
    def perform_create(self, serializer):
        created_object = serializer.save()
        send_mail('Subject here','Here is the message.','[email protected]', 
            [created_object.email],  fail_silently=False,)

send email when object has been created

for create a link and verify follow this tutorial doc

Sign up to request clarification or add additional context in comments.

Comments

0

You can try django-djoser link.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.