When I edit a profile, how do I make the system automatically send a confirmation email if the email is changed - Django

So... My main intention is that when a user edits his/her account and changes the email, the system has to change all the other info except email and send an email to the new email (inputted by the user) with a confirmation link. And once clicked, the system has to redirect the user to another page and change the email for that account. Please tell me how I can do this.

my view:

class NormalUserEditView(generic.UpdateView):
    form_class = EditProfileFormNormal
    template_name = 'authentication/edit_normalprofile.html'
    success_url = reverse_lazy('profile')

    def form_valid(self, form):
        messages.success(self.request, f'Account Edit: Successful')
        return super().form_valid(form)

    def get_object(self):
        return self.request.user

For the email thing I was referring to this view:

def register_user(request):
    if request.method == "POST":
        form = RegisterUserForm(request.POST)
        if form.is_valid():
            myuser = User.objects.create_user(
            myuser.is_active = False

            # "Thank You For Registering" Email
            subject = "Welcome To some website"
            body = "Hello " + myuser.first_name + "!\n" + "Thank you for registering to some website. Your account has been registered. However, it has not been activated. We have sent you another email that contains a link. In order to activate your account you must click on that link. The email will be sent shortly. \nNOTE: If you have not created an account in some website, please ignore this email. \n \nsome website."
            from_email = settings.EMAIL_HOST_USER
            to_list = [myuser.email]

            send_mail(subject, body, from_email, to_list, fail_silently=True)

            # Confirm Email

            current_site = get_current_site(request)
            email_subject = "Confirm Your Email - some website"
            email_message = render_to_string('authentication/email_confirmation.html', {
                    'name': myuser.first_name,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(myuser.pk)),
                    'token': generate_token.make_token(myuser),
            email = EmailMessage(

            messages.success(request, ("Registration: Successful!"))

            return redirect('confirm-address-page')
        form = RegisterUserForm()

    return render(request, 'authentication/register.html', {

this for token generating:

from django.contrib.auth.tokens import PasswordResetTokenGenerator
from six import text_type

class TokenGenerator(PasswordResetTokenGenerator):
    def _make_hash_value(self,user,timestamp):
        return (
        text_type(user.pk) + text_type(timestamp) 
        # text_type(user.profile.signup_confirmation)

generate_token = TokenGenerator()

this for the forms:

class RegisterUserForm(UserCreationForm):
    email = forms.EmailField(widget=forms.EmailInput(attrs={'class': 'form-control'}))
    first_name = forms.CharField(max_length=50, widget=forms.TextInput(attrs={'class': 'form-control'}))
    last_name = forms.CharField(max_length=50, widget=forms.TextInput(attrs={'class': 'form-control'}))

    class Meta:
        model = User
        fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2')

    def __init__(self, *args, **kwargs):
        super(RegisterUserForm, self).__init__(*args, **kwargs)

        self.fields['username'].widget.attrs['class'] = 'form-control'
        self.fields['password1'].widget.attrs['class'] = 'form-control'
        self.fields['password2'].widget.attrs['class'] = 'form-control'

email_confirmation.html :

{% autoescape off %}

Welcome to Some Website

Hello {{ name }}!

Please Confirm your email by clicking on the following link:

Confirmation Link:

http://{{ domain }}{% url 'activate' uidb64=uid token=token %}

{% endautoescape %}
Back to Top