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:


In my view, I perform the send_mail():


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, like this:


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