Django 密码重置。不发送邮件
我正在尝试使 django 密码重置正常工作,但重置电子邮件未发送。
我知道我的电子邮件已正确配置,因为以下内容在 shell 和我的视图之一中都有效(我使用它来向自己获取支持电子邮件)。
from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.',
'[email protected]',['[email protected]'], fail_silently=False)
我可以进入我的重置密码视图(密码/重置/),在我给它我的电子邮件后,它正确地将我重定向到密码/重置/完成/,但它没有t 发送电子邮件。
这是我的 urls.py
:
(r'^password/reset/$','django.contrib.auth.views.password_reset'),
(r'^password/reset/done/$','django.contrib.auth.views.password_reset_done'),
(r'^password/reset/confirm/$','django.contrib.auth.views.password_reset_confirm'),
(r'^password/reset/complete/$','django.contrib.auth.views.password_reset_confirm'),
(r'^password/change/$','django.contrib.auth.views.password_change'),
(r'^password/change/done/$','django.contrib.auth.views.password_change_done'),
这是我的 password_reset_form.html
:
<html>
<head>
<link rel="stylesheet" type="text/css" href="/media/css/style_login.css" />
<title>Información de acceso requerida</title>
</head>
<body>
<div id="wrapper">
<h1>Recuperar password</h1>
<p>Utilice este formulario cuando desee recuperar el password para su usuario.</p>
{% if form.errors %}
<p>No hay un usuario registrado con ese correo electronico.</p>
{% endif %}
<form method="post" action="{% url django.contrib.auth.views.password_reset_done %}">
{% csrf_token %}
{{ form }}
<input class="login" type="submit" value="Recuperar" />
</form>
</div>
</body>
有什么想法吗?谢谢
I'm trying to get the django password reset working but the reset email does not get sent.
I know my email is properly configured because the following works both in the shell and in one of my views (I'm using it to get support email to myself).
from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.',
'[email protected]',['[email protected]'], fail_silently=False)
I can get to my reset password view (password/reset/) and after I give it my email it correctly redirects me to password/reset/done/ but it doesn't sends the email.
Here's my urls.py
:
(r'^password/reset/
Here's my password_reset_form.html
:
<html>
<head>
<link rel="stylesheet" type="text/css" href="/media/css/style_login.css" />
<title>Información de acceso requerida</title>
</head>
<body>
<div id="wrapper">
<h1>Recuperar password</h1>
<p>Utilice este formulario cuando desee recuperar el password para su usuario.</p>
{% if form.errors %}
<p>No hay un usuario registrado con ese correo electronico.</p>
{% endif %}
<form method="post" action="{% url django.contrib.auth.views.password_reset_done %}">
{% csrf_token %}
{{ form }}
<input class="login" type="submit" value="Recuperar" />
</form>
</div>
</body>
Any ideas? Thanks
,'django.contrib.auth.views.password_reset'),
(r'^password/reset/done/
Here's my password_reset_form.html
:
Any ideas? Thanks
,'django.contrib.auth.views.password_reset_done'),
(r'^password/reset/confirm/
Here's my password_reset_form.html
:
Any ideas? Thanks
,'django.contrib.auth.views.password_reset_confirm'),
(r'^password/reset/complete/
Here's my password_reset_form.html
:
Any ideas? Thanks
,'django.contrib.auth.views.password_reset_confirm'),
(r'^password/change/
Here's my password_reset_form.html
:
Any ideas? Thanks
,'django.contrib.auth.views.password_change'),
(r'^password/change/done/
Here's my password_reset_form.html
:
Any ideas? Thanks
,'django.contrib.auth.views.password_change_done'),
Here's my password_reset_form.html
:
Any ideas? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我应该提到我正在使用 Hostgator 作为我的提供商。所以这是我的settings.py
上面的设置有效!
I should have mention I'm using hostgator as my provider. So this is my settings.py
The above settings work!
就我而言,我使用
create_user()
创建了用户。我的想法是创建一堆帐户,然后告诉人们他们可以进入密码重置表单来设置密码。我认为如果你需要告诉他们“使用密码“welcome123”然后不要忘记修改你的密码”之类的,那就太糟糕了。我发现如果我没有传递
Password='foo'
或者如果我将Password=None
传递给create_user()
密码重置是< em>未发送。这是因为 Django 有时会使用空密码来知道它不需要在本地进行身份验证,而是使用 LDAP 等。所以现在我这样做:
我可以指导人们为他们的新帐户使用密码重置功能。不过,我认为如果 create_user 中有一个选项可以自动向用户发送用于帐户激活的电子邮件,那就太棒了!
In my case I created the users using
create_user()
. My idea was to create a bunch of accounts and then tell people they could go to the password reset form to set their password. I think it sucks if you need to tell them 'Use password "welcome123" and then don't forget to modify your password' or such.I found out if I did not pass
Password='foo'
or also if I passedPassword=None
tocreate_user()
password resets are not sent. This is because Django sometimes uses an empty password to know that it does not need to authenticate locally, but rather use LDAP or such.So now I do this:
And I can direct people to use the password reset function for their new accounts. I think it would be awesome if I had an option in create_user to automatically send emails for account activation to users, though!
您需要添加默认地址,例如:
DEFAULT_FROM_EMAIL = '[email protected]'
我现在看到它在评论中,但会添加它以防万一有人也想念他们。
You need to add a default from address e.g:
DEFAULT_FROM_EMAIL = '[email protected]'
I see now it is in the comments but will add it here in case anyone misses them too.