在没有浏览器的情况下在 django 中触发密码重置电子邮件? [英] Trigger password reset email in django without browser?

查看:13
本文介绍了在没有浏览器的情况下在 django 中触发密码重置电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用 django.contrib.auth.views.password_reset 发送密码重置电子邮件但不使用浏览器 - password_reset 需要一个填充表单,有没有办法我可以通过编程方式创建它并发送电子邮件?

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?

推荐答案

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)

这篇关于在没有浏览器的情况下在 django 中触发密码重置电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆