【问题标题】:Is there a way to change the password_reset_confirm link sent by django?有没有办法改变django发送的password_reset_confirm链接?
【发布时间】:2015-02-10 04:11:01
【问题描述】:

我正在使用 django 内置身份验证。当密码重置电子邮件发送给用户时,它包含一个链接。我希望能够简单地将链接更改为其他内容。因为我有一个前端 angularJS 应用程序。因此,我希望电子邮件中的链接成为我的 AngularApp 可以拦截的内容。

这是发送电子邮件https://github.com/django/django/blob/master/django/contrib/admin/templates/registration/password_reset_email.html#L6的模板

我只是想将{% url 'password_reset_confirm' uidb64=uid token=token %} 更改为http://localhost:8001/passwordResetConfirm/uid/token

【问题讨论】:

  • 如果您在模板目录中创建registration/password_reset_email.html 模板,那么您可以将链接更改为您想要的任何内容。但是,如果您不在 url 中包含令牌,我看不出重置密码有什么用处。

标签: django authentication


【解决方案1】:

只需使用名称'password_reset_confirm' 重新定义网址包含django.contrib.auth.urls。如果有多个同名的 url,则 URL 调度程序使用最后一次出现:

from django.contrib.auth import views as auth_views

urlpatterns = patterns('',
    ...
    url(r'^accounts/', include('django.contrib.auth.urls')),
    url(r'^passwordResetConfirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})$',
                              auth_views.password_reset_confirm,
                              name='password_reset_confirm'),
)

【讨论】:

    猜你喜欢
    • 2015-02-16
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 2020-04-27
    • 2020-12-07
    • 1970-01-01
    • 1970-01-01
    • 2013-08-30
    相关资源
    最近更新 更多