Trigger password reset email in django without browser?

拈花ヽ惹草 提交于 2019-12-18 16:27:12

问题


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?


回答1:


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:


You can just use django.contrib.auth.forms.PasswordResetForm and populate it with data like this:

form = PasswordResetForm({'email':'sample@sample.com'})

The sending of email is done upon save().



来源:https://stackoverflow.com/questions/5594197/trigger-password-reset-email-in-django-without-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!