【发布时间】:2019-12-31 08:06:07
【问题描述】:
我正在使用 django Rest Auth 实现密码重置,当来自 reactjs 前端的请求命中时我需要做两件事但它会将我发送到本机 Rest UI PasswordConfirmView。
我希望,当用户点击请求时,它应该使用我的模板,即 password_reset.html、password_reset_confirm.html、password_reset_done.html... 我们在模板/应用程序名目录中创建的模板 我的尝试:
urls.py:
urlpatterns=[
url(
r'^rest-auth/password/reset/$',
PasswordResetView.as_view(),
name='password_reset',
),
url(
r'^rest-auth/password/reset/confirm/'
r'(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
PasswordResetConfirmView.as_view(),
name='password_reset_confirm'),
]
身份验证系统/模板:
password_reset_confirm.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{% if validlink %}
<h3>Change password</h3>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Change password</button>
</form>
{% else %}
<p>
The password reset link was invalid, possibly because it has already been used.
Please request a new password reset.
</p>
{% endif %}
</body>
</html>
我知道上述方法较少但我想知道如何使它工作已发送,当我单击电子邮件中的链接时,我想显示我的模板,令牌和 uid 应该从模板传递,我已准备好所有模板但不知道如何与 Django Rest Auth 一起使用。
【问题讨论】:
-
这不是 REST 视图 (API),它只是 allauth 包中的普通视图,因此您不必更改任何 URL(如果您更改了 @ 987654323@ 在您的主要网址中)。只需将模板放在 templates 目录中的 account 目录中,即可覆盖 allauth 使用的模板。另外我认为模板名称不正确,应该是 authsystem/templates/account/password_reset_from_key.html
标签: django reactjs django-rest-framework django-urls django-rest-auth