Python 与用户相关的模型的某些属性的设置值
我有一个与用户相关的模型(关系:OneToOne),在这个模型中,我有一个名为email\u confirmation的字段。我可以访问此字段,但无法更新它 型号.pyPython 与用户相关的模型的某些属性的设置值,python,django,Python,Django,我有一个与用户相关的模型(关系:OneToOne),在这个模型中,我有一个名为email\u confirmation的字段。我可以访问此字段,但无法更新它 型号.py class Profile(models.Model): profile_user = models.OneToOneField(User, ...) profile_email_confirmation = models.BooleanField(default=False
class Profile(models.Model):
profile_user = models.OneToOneField(User, ...)
profile_email_confirmation = models.BooleanField(default=False)
def mail_confirmation(request, uidb64, token):
uid = force_text(urlsafe_base64_decode(uidb64))
user = User.objects.get(pk=uid)
...
if user is not None and account_activation_token.check_token(user, token):
user.profile.profile_email_confirmation = True
user.save() #This isn't working and doesn't cause any error
login(request, user) #This is working
return redirect('/home') #This is working
视图.py
class Profile(models.Model):
profile_user = models.OneToOneField(User, ...)
profile_email_confirmation = models.BooleanField(default=False)
def mail_confirmation(request, uidb64, token):
uid = force_text(urlsafe_base64_decode(uidb64))
user = User.objects.get(pk=uid)
...
if user is not None and account_activation_token.check_token(user, token):
user.profile.profile_email_confirmation = True
user.save() #This isn't working and doesn't cause any error
login(request, user) #This is working
return redirect('/home') #This is working
这个函数没有引起任何错误,所以我不知道是什么问题,我实际上得到了重定向到/home(已记录)。我还可以访问字段配置文件\u电子邮件\u确认
当我在管理页面中检查模型时,profile\u email\u confirmation字段没有被更改 您还需要保存配置文件实例
if user is not None and account_activation_token.check_token(user, token):
user.profile.profile_email_confirmation = True
user.profile.save() # add this extra line
user.save()
login(request, user)
return redirect('/home')
如果用户不是None和帐户\u激活\u令牌。检查\u令牌(用户,令牌):
user.profile.profile\电子邮件\确认=True
user.profile.save()#添加此额外行
user.save()
登录(请求、用户)
返回重定向(“/home”)
您还需要保存配置文件实例
if user is not None and account_activation_token.check_token(user, token):
user.profile.profile_email_confirmation = True
user.profile.save() # add this extra line
user.save()
login(request, user)
return redirect('/home')
如果用户不是None和帐户\u激活\u令牌。检查\u令牌(用户,令牌):
user.profile.profile\电子邮件\确认=True
user.profile.save()#添加此额外行
user.save()
登录(请求、用户)
返回重定向('/home')