Search code examples
djangodjango-rest-frameworkdjango-allauthdjango-rest-auth

django-rest-auth password reset sending wrong domain in email


I'm trying to test my password reset configuration on my localhost using django-rest-auth. The email verification and registration work, and I can trigger a password reset event and send an email, but the email contains the wrong domain. Right now it is passing a link containing my-site.com as the domain instead of 0.0.0.0:8000 as the domain. I am running the app inside a docker container which is why it is 0.0.0.0:8000 instead of 127.0.0.1:8000.

Current result:

You're receiving this email because you requested a password reset for your user account at My Site.

Please go to the following page and choose a new password:

http://my-site.com/auth/password-reset/confirm/OA/55d-7dc2614593146ac3ce82/

Your username, in case you've forgotten: testaccount

Thanks for using our site!

The My Site team

Expected result

You're receiving this email because you requested a password reset for your user account at My Site.

Please go to the following page and choose a new password:

http://0.0.0.0:8000/auth/password-reset/confirm/OA/55d-7dc2614593146ac3ce82/

Your username, in case you've forgotten: testaccount

Thanks for using our site!

The My Site team

My url file for my registration is:

from django.urls import path, include
from allauth.account.views import ConfirmEmailView
from . import views

urlpatterns = [
    path('registration/account-email-verification-sent/', views.null_view, name='account_email_verification_sent'),
    path('registration/account-confirm-email/<key>', ConfirmEmailView.as_view(), name='account_confirm_email'),
    path('registration/complete/', views.complete_view, name='account_confirm_complete'),
    path('password-reset/confirm/(<uidb64>/<token>/', views.null_view, name='password_reset_confirm'),
    path('', include('rest_auth.urls')),
    path('registration/', include('rest_auth.registration.urls')),
]

I ran across another post that suggested changing the site id, but I'm not sure this is correct.

How do I get it to pass the currently served domain instead of the site id domain?


Solution

  • Easy Solution

    Step 1: Go to /admin/sites/site/, You'll see something similar as below, enter image description here

    Step 2: Edit the existing entry with following value then save it
    Domain name: 0.0.0.0:8000
    Display name: Your Site Name
    enter image description here