【发布时间】:2021-02-01 05:00:37
【问题描述】:
我正在使用 Django Rest Auth 和 Django All Auth。
当我点击端点 /rest-auth/password/reset/ (POST) 时,我收到一封电子邮件,其中包含重置密码的 URL。
但是 URL 不起作用,因为域始终是 example.com 和 uid token 不能像下面那样正常工作...
http://example.com/password/reset/confirm/(%3FPMzQ%5B0-9A-Za-z_%5C-%5D+)/(%3FP5ku-afb8832e99157c02f452%5B0-9A-Za-z%5D%7B1,13%7D-%5B0-9A-Za-z%5D%7B1,20%7D)/$
我已覆盖 PasswordResetSerializer 以使用我的电子邮件模板引用 to this article
我该如何解决这种情况?
代码如下:
序列化器.py
from rest_auth.serializers import PasswordResetSerializer
class CustomPasswordResetSerializer(PasswordResetSerializer):
def get_email_options(self):
print("check override")
return {
'email_template_name': 'password_reset_key_message.txt',
}
password_reset_key_message.txt
A password reset has been requested.
Click the link below to continue.
{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}
如果我将{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} 的一部分更改为{{ password_reset_url }},则电子邮件不包含任何网址
当我像 berow 一样在 def get_email_options(self) 中添加 'domain_override' 时,
from rest_auth.serializers import PasswordResetSerializer
class CustomPasswordResetSerializer(PasswordResetSerializer):
def get_email_options(self):
print("check override")
return {
'domain_override': 'localhost:8000',
'email_template_name': 'password_reset_key_message.txt',
}
网址变成下面这样,
http://localhost:8000/password/reset/confirm/(%3FPMzQ%5B0-9A-Za-z_%5C-%5D+)/(%3FP5ku-afb8832e99157c02f452%5B0-9A-Za-z%5D%7B1,13%7D-%5B0-9A-Za-z%5D%7B1,20%7D)/$
在这种情况下,我可以指定一个域,但是uid 和token 仍然不起作用...
蟒蛇:3.7.5
Django:2.2.2
django-allauth:0.41.0
django-rest-auth:0.9.5
djangorestframework:3.12.1
【问题讨论】:
标签: django-rest-framework django-allauth django-rest-auth