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