【问题标题】:Sending password reset email with django使用 django 发送密码重置电子邮件
【发布时间】:2021-07-28 22:01:24
【问题描述】:

我有一个正在开发的小博客。在用户仅使用电子邮件注册后,我想发送一封电子邮件,其中包含指向密码重置页面的链接。

def email_signUp(request):
    if request.method == 'POST':
        if 'email_subscription' in request.POST:
            form = EmailForm(request.POST)
            if form.is_valid():
                username = form.cleaned_data['email'].split('@')[0]
                email = form.cleaned_data['email']
                password1 = passgen()

                User.objects.create_user(username=username, email=email, password=password1)

如何发送电子邮件?我已经可以通过'password_reset/'访问密码重置页面

正在使用

if DEBUG:
    EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

【问题讨论】:

    标签: django


    【解决方案1】:

    这是快速示例 ->

    from django.core.mail import send_mail
    
    send_mail(
        'Subject here',
        'Here is the message.', #after you will create user object you can send in message api url like localhost:8000/password_reset/
        'from@example.com',
        ['to@example.com'],
        fail_silently=False,
    )
    

    【讨论】:

      猜你喜欢
      • 2013-12-18
      • 1970-01-01
      • 2019-12-01
      • 2020-09-26
      • 1970-01-01
      • 2015-11-26
      • 1970-01-01
      • 2021-08-05
      • 1970-01-01
      相关资源
      最近更新 更多