Django 忘记密码功能更改默认邮箱

2 投票
2 回答
3344 浏览
提问于 2025-04-16 22:52

我为我的网站创建了一个“忘记密码”的功能,使用的是Django自带的password_reset函数。这个函数会发送一封邮件,内容如下:

You're receiving this e-mail because you requested a password reset for your user account at example.com.

Please go to the following page and choose a new password:

http://example.com/reset/3/2zf-fe162b1d79f1b85c3630/

Your username, in case you've forgotten: Angie

Thanks for using our site!

The example.com team

我应该在哪里修改这封邮件的内容呢?

2 个回答

0

对于那些遇到这个错误的人:

Caught NoReverseMatch while rendering: for line {% url 'views.cust_password_reset_confirm' uidb36=uid token=token %}

在尝试发送重置密码的邮件时,要注意一下 password_reset_confirm 的网址。它应该是类似这样的:

(r'^password-reset-confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$','django.contrib.auth.views.password_reset_confirm', {'template_name':'accounts/password_reset_confirm.html', 'post_reset_redirect':'/accounts/logout/'}),
6

这个邮件的默认模板在 django/contrib/admin/templates/registration/password_reset_email.html 这个位置。你可以通过在你的应用目录下创建一个自己的模板 templates/registration/password_reset_email.html 来覆盖它,就像平常那样。

撰写回答