当用户请求重置密码时,我想发送自定义电子邮件。我在 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',
],
},
},
]
然后我在项目根目录中创建了模板文件夹,在其中创建了一个注册文件夹,并在其中放置了password_reset_email.html。
这是我在谷歌搜索一段时间后发现的问题的确切解决方案,但这对我不起作用。我错过了什么?