在django中确认我的电子邮件后,帐户未激活

问题描述

我在django中编写了一些有关通过验证电子邮件进行注册的代码,并且该电子邮件已发送给我,并且我确认了,但是我的帐户未激活。 我不知道问题出在我的激活功能上还是什么 这是我得到的错误:

enter image description here

这是我的激活功能:

def activate(request,uidb64,token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except(TypeError,ValueError,OverflowError,User.DoesNotExist):
        user = None
    if user is not None and acc_activation.check_token(user,token):
        user.is_active = True
        user.save()
        login(request,user)
        # return redirect('home')
        return HttpResponse('Thank you for your email confirmation. Now you can login your account.')
    else:
        return HttpResponse('Activation link is invalid!')

和我的activation_email.html代码:

    {% autoescape off %}
Hi {{ user.username }},pleace click here to confirm your registration,http://{{ domain }}{% url 'activate' uidb64=uid token=token %}
{% endautoescape %}

解决方法

在您的逻辑中添加user.profile.email_confirmed = True

    if user is not None and acc_activation.check_token(user,token):
        user.is_active = True
        user.profile.email_confirmed = True
        user.save()
        login(request,user)
        # return redirect('home')
        return HttpResponse('Thank you for your email confirmation. Now you can login your account.')

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...