小编Ach*_*ese的帖子

Django:尝试验证电子邮件验证 OTP 时出错

我在注册时向用户发送一封电子邮件,并将 otp 与电子邮件一起获取,我有一个单独的验证模型,如下所示,我面临的错误与{"message": "This OTP is invalid"}verifyEmail 视图中的代码和平有关(在下面)

class Verify(models.Model):
    email = models.EmailField(
        _("Email"), max_length=254, unique=True, default=None, blank=True, null=True)
    otp = IntegerRangeField(
        min_value=111111, max_value=999999, blank=True, null=True)
    created_at = models.DateTimeField(
        _("created at"), auto_now=False, auto_now_add=True, blank=False)
    expires_at = models.DateTimeField(null=True)

    def __str__(self) -> str:
        return self.email
Run Code Online (Sandbox Code Playgroud)

我如何发送电子邮件

def send_opt_email(email, firstname, lastname):
    otp = random.randint(100000, 999999)
    subject = "Email verification"
    message = "Email verification"
    html_message = loader.render_to_string(
        "email_verify.html",
        {
            "firstname": firstname,
            "lastname": lastname,
            "otp": otp,
        },
    )
    email_from = settings.EMAIL_HOST_USER
    send_mail(
        subject, …
Run Code Online (Sandbox Code Playgroud)

django django-views python-3.x django-rest-framework

1
推荐指数
1
解决办法
410
查看次数