重置电子邮件给我发example.com网址

时间:2019-06-10 18:21:23

标签: django django-rest-framework django-rest-auth

当我尝试使用密码password / reset时,请给我发送带有此URL的邮件

http://example.com/password-reset/confirm/MjM/572-52a21bbd1b80e9377f98/有什么想法吗?

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",
)

1 个答案:

答案 0 :(得分:1)

如果您在设置中使用 SITE_ID=1 ,显然会发生这种情况。 django-all-auth 包使用 {em> domain 字段的值em> SITE_ID ,同时创建 重置密码邮件

因此,您可以选择

1。更改现有 domain

SITE_ID的值

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。创建新的 Site 实例,并将新创建的站点ID放入settings.py

在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)

现在,您将获得新的 网站ID ,并将其放入settings.py中,

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

注意

这些操作( 1 2 )也可以通过Django管理控制台完成。