我已经尝试过针对类似问题找到的解决方案,但没有一个对我有用。
我使用的是 Angular 前端 + DRF + Django Rest Auth,对于确认 url,我能够通过添加看起来像这样的自定义适配器来覆盖它以指向我的前端,
class AccountAdapter(DefaultAccountAdapter):
def send_mail(self, template_prefix, email, context):
context['activate_url'] = settings.URL_FRONT + \
'access/verify-email/' + context['key']
msg = self.render_mail(template_prefix, email, context)
msg.send()
with URL_FRONT = 'http://localhost:8080/app/#/'
作为将用户定向到客户端的设置。
我的问题是对密码重置网址实施同样的事情。我希望它从URL_FRONT
设置并附加令牌就像我所确认的那样。
解决这个问题的最佳方法是什么?
看起来像 django-rest-auth 使用django.contrib.auth.forms.PasswordResetForm
处理这个:https://github.com/Tivix/django-rest-auth/blob/master/rest_auth/serializers.py#L183 https://github.com/Tivix/django-rest-auth/blob/master/rest_auth/serializers.py#L183
并根据Django 文档 https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.views.PasswordResetDoneView您可以传递自己的电子邮件模板(注意:Django 1.11 中有一个重大更改,因此请确保使用您的 Django 版本的文档)。默认模板是registration/password_reset_form.html
。您可以使用自己的方法覆盖它PasswordResetSerializer
(延伸rest_auth.serializers.PasswordResetSerializer
) 在里面django-rest-auth 配置 http://django-rest-auth.readthedocs.io/en/latest/configuration.html.
在那里你可以覆盖获取电子邮件选项() https://github.com/Tivix/django-rest-auth/blob/master/rest_auth/serializers.py#L161方法并设置自己的模板
def get_email_options(self):
return {
'email_template_name': 'path/to/your/txt_template.html',
'html_email_template_name': 'path/to/your/html_template.html',
}
或者也许只需将您的 URL 传递为success_url
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)