如何正确使用lib django-rest-passwordreset

时间:2019-07-10 17:17:01

标签: django-rest-framework

我像自述文件一样配置django-rest-passwordreset lib,因此我可以正确发送和接收电子邮件,但是它们为空白,因为我需要配置模板以正确发送信息

我用我的个人电子邮件配置了环境变量(仅测试),并且我收到了正确的消息,在教程中说我需要创建两个模板,电子邮件/ user_reset_password.html和电子邮件/ user_reset_password.txt,但是我没有知道如何配置它以发送信息。

@receiver(reset_password_token_created)
def password_reset_token_created(sender, instance, reset_password_token, *args, **kwargs):
    """
    Handles password reset tokens
    When a token is created, an e-mail needs to be sent to the user
    :param sender: View Class that sent the signal
    :param instance: View Instance that sent the signal
    :param reset_password_token: Token Model Object
    :param args:
    :param kwargs:
    :return:
    """
    # send an e-mail to the user
    context = {
        'current_user': reset_password_token.user,
        'username': reset_password_token.user.username,
        'email': reset_password_token.user.email,
        'reset_password_url': "{}?token={}".format(reverse('password_reset:reset-password-request'), reset_password_token.key)
    }

    # render email text
    email_html_message = render_to_string('email/user_reset_password.html', context)
    email_plaintext_message = render_to_string('email/user_reset_password.txt', context)

    msg = EmailMultiAlternatives(
        # title:
        "Password Reset for {title}".format(title="Some website title"),
        # message:
        email_plaintext_message,
        # from:
        "gustavoasnogueira@gmail.com",
        # to:
        [reset_password_token.user.email]
    )
    msg.attach_alternative(email_html_message, "text/html")
       msg.send()

我没有收到任何错误消息,但是电子邮件中没有重新定义链接

0 个答案:

没有答案