密码重置确认视图不生成邮件



我正在尝试在我的 django 应用程序中设置一个"忘记密码"链接,使用默认的身份验证视图,但在特定路径中使用我自己的模板。我能够实现重置表单和"完成"wview,但通常邮件没有生成。也不是错误。

这是我 urls.py 文件:

path('password-reset/', PasswordResetView.as_view(
template_name='auth/reset_password/reset.html',
subject_template_name='auth/reset_password/mail_subject.txt',
email_template_name='auth/reset_password/mail_body.html',
success_url='/password-reset/done/'
), name='password_reset'),
path('password-reset/done/', PasswordResetDoneView.as_view(
template_name='auth/reset_password/done.html'
), name='password_reset_done'),
path('password-reset-confirm/<uidb64>/<token>/',
PasswordResetConfirmView.as_view(
template_name='auth/reset_password/confirm.html'
), name='password_reset_confirm'),
path('password-reset-complete/',
PasswordResetCompleteView.as_view(
template_name='auth/reset_password/complete.html'
), name='password_reset_complete'),

我mail_body.html:

{% autoescape off %}
To initiate the password reset process for your {{ user.get_username }} TestSite Account,
click the link below:{% url 'password_reset_confirm' uidb64=uid token=token %}
If clicking the link above doesn't work, please copy and paste the URL in a new browser
window instead.
Sincerely,
The Epicups Team
{% endautoescape %}

我在想也许我的用户模型是我的问题,因为我使用邮件作为用户名,所以这里是:

class CustomUser(AbstractBaseUser, PermissionsMixin): 
email= models.EmailField(_('email'), unique=True)
vat_number =  models.CharField(_('vat_number'), max_length=9)
company_name = models.CharField(_('company_name'), max_length=255)
contact_person = models.CharField(_('contact_person'), max_length=255)
host_id = models.CharField(_('host_id'), max_length=255, blank=True)
last_login_at = models.DateTimeField(_('last_login_at'), auto_now_add=True)
current_login_at = models.DateTimeField(_('current_login_at'), auto_now_add=True)
last_login_ip = models.CharField(_('last_login_ip'), max_length=100, blank=True)
current_login_ip = models.CharField(_('current_login_ip'), max_length=100, blank=True)
login_count = models.BigIntegerField(_('login_count'), null=True)
is_active = models.BooleanField(_('is_active'), null=True)
confirmed_at = models.DateTimeField(_('current_login_at'), auto_now_add=True)
role_id = models.BigIntegerField(_('login_count'),  null=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['vat_number','company_name','contact_person']
objects =  MyUserManager()

这可能吗?如果是这样,我不知道如何解决它。正在发生success_url重定向。

我 settings.py:

EMAIL_HOST = 'localhost'
DEFAULT_FROM_EMAIL = 'example@example.com'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' 

您需要在模型中指定EMAIL_FIELD

EMAIL_FIELD = 'email'
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['vat_number','company_name','contact_person']

最新更新