【发布时间】:2022-03-14 20:05:12
【问题描述】:
当用户请求重置密码时,我想发送自定义电子邮件。我在 django 中使用 dj_rest_auth。以下是我所做的: 1. 定义了一个继承自 dj_rest_auth 的 PasswordResetSerializer 的自定义序列化器
class CustomPasswordResetSerializer(PasswordResetSerializer):
def get_email_options(self):
return {
'html_mail_template_name': 'registration/password_reset_email.html',
}
然后在settings.py中指向这个序列化器:
REST_AUTH_SERIALIZERS = {
'LOGIN_SERIALIZER': 'users.serializers.CustomLoginSerializer',
'PASSWORD_RESET_SERIALIZER': 'users.serializers.CustomPasswordResetSerializer',
}
然后在settings.py中配置模板
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
然后我在项目根目录下创建了 templates 文件夹,在其中创建了一个 registration 文件夹,并将 password_reset_email.html 放入其中。
这是我在谷歌搜索一段时间后发现的问题的确切解决方案,但这对我不起作用。我错过了什么?
【问题讨论】:
标签: django django-rest-framework django-allauth dj-rest-auth