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

Reset email send me example.com url


When I try to use the password password/reset send me a mail with this this url

http://example.com/password-reset/confirm/MjM/572-52a21bbd1b80e9377f98/ Any ideas??

settings.py


SITE_ID = 1
#Registro simple sin correo
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

#Login no mail
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_CONFIRM_EMAIL_ON_GET = True
ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = 
reverse_lazy('account_confirm_complete')
ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = 
reverse_lazy('account_confirm_complete')
ACCOUNT_USERNAME_REQUIRED = False
#Following is added to enable registration with email instead of username
AUTHENTICATION_BACKENDS = (
 # Needed to login by username in Django admin, regardless of `allauth`
 "django.contrib.auth.backends.ModelBackend",

 # `allauth` specific authentication methods, such as login by e-mail
 "allauth.account.auth_backends.AuthenticationBackend",
)

Solution

  • This will obviously happen if you use SITE_ID=1 in your settings. The django-all-auth package uses the value of domain field of SITE_ID while creating a reset-password mail.

    So, you can do either,

    1. Change the value of domain of existing SITE_ID

    Run the script in your Django Shell

    from django.conf import settings
    from django.contrib.sites.models import Site
    
    site = Site.objects.get(id=settings.SITE_ID)
    site.domain = "your.required.domain.com"
    site.name = "Some Readable Name for Your Site"
    site.save()
    

    2. Create new Site instance and put newly created site id in settings.py

    Run this on django shell,

    from django.contrib.sites.models import Site
    
    site = Site.objects.create(domain="your.required.domain.com", name="Some Readable Name for Your Site")
    print(site.id)
    

    Now, you'll get the new site id, put that in settings.py as,

    #settings.py
    SITE_ID = 123 # here "123" is the id of your newly creted site object
    

    Note

    These things(1 and 2) can also be done via Django Admin console.