Using custom email backed and password reset/email form

I am using a custom EMAIL_BACKEND. The email setup is successful. I can get the email in my own email account.

When I use the password reset form, I can also get the email in my own account. This is how I did it. I specify a view:

    path(route="accounts/password_reset/", 
         view=home_views.my_password_reset_view,
         name="my_password_reset_view"),

In my view, I perform the send_mail():

send_mail(subject=password_reset_subject,
              message=password_reset_email,
              from_email=from_email,
              recipient_list=[user_email],
              html_message=password_reset_email,
             )

In the reset_link, I set the following:

protocol = "http"
domain = request.get_host()
reset_link = (f"{protocol}://{domain}/accounts/reset/{uidb64}/{token}/")
password_reset_email = format_html(
            "<html>... <a href='{}'>Reset password page</a></html>", reset_link
            )
            password_reset_subject = "Password reset request"

The password_reset_email is a string that I set. The registrations/password_reset_email.html will give errors about the template.

But, the problem is with the uid and token. I don’t know to get the uid and the token.

Do you have any idea how to obtain the uid and the token?

Welcome @liewchooichin !

The code for the Django-provided PasswordResetForm is in django.contrib.auth.forms. The .save() method of that form shows how those fields are generated.

Is there a reason why you’re building this yourself instead of using the Django library?

I got it. It is the DEFAULT_FROM_EMAIL. It must be set in the settings.py, like this:

DEFAULT_FROM_EMAIL="<DoNotReply@example.com>"

Once I set this, I can use the default bulit-in password reset successfully.