I want to be able to send a password reset email using django.contrib.auth.views.password_reset but without using the browser - password_reset needs a populated form, is there a way I can create this programmatically and get the email sent?
我希望能够使用django.contrib.auth.views.password_reset发送密码重置电子邮件但不使用浏览器 - password_reset需要填充表单,有没有办法可以编程方式创建并发送电子邮件?
2 个解决方案
#1
11
from django.contrib.auth.forms import PasswordResetForm
def reset_password(email, from_email, template='registration/password_reset_email.html'):
"""
Reset the password for all (active) users with given E-Mail adress
"""
form = PasswordResetForm({'email': email})
return form.save(from_email=from_email, email_template_name=template)
#2
5
You can just use django.contrib.auth.forms.PasswordResetForm and populate it with data like this:
您可以使用django.contrib.auth.forms.PasswordResetForm并使用以下数据填充它:
form = PasswordResetForm({'email':'sample@sample.com'})
The sending of email is done upon save().
发送电子邮件是在save()时完成的。
#1
11
from django.contrib.auth.forms import PasswordResetForm
def reset_password(email, from_email, template='registration/password_reset_email.html'):
"""
Reset the password for all (active) users with given E-Mail adress
"""
form = PasswordResetForm({'email': email})
return form.save(from_email=from_email, email_template_name=template)
#2
5
You can just use django.contrib.auth.forms.PasswordResetForm and populate it with data like this:
您可以使用django.contrib.auth.forms.PasswordResetForm并使用以下数据填充它:
form = PasswordResetForm({'email':'sample@sample.com'})
The sending of email is done upon save().
发送电子邮件是在save()时完成的。