python - 为什么 Django 更新对象第一次没有触发?
问题描述
我有两个功能。我的第一个函数将布尔值更新为 True 为 False。我的第一个函数正常工作,但我的第二个函数没有将对象 False 更新为 True。如果我尝试两次然后第二次我的第二个函数将对象 False 更新为 True。我不明白为什么它第一次不更新?
这是我的代码:
function1 #这个函数正常工作
视图.py
def ForgetPassword(request):
if request.method == "POST":
.....my others code
profile_obj = UserProfile.objects.get(user=user_obj)
profile_obj.email_confirmed = False
profile_obj.save()
.....my others code
function2 #this 函数无法正常工作 如果我尝试两次然后第二次我的 this 函数将对象 False 更新为 True:
class ChangePassword_link(View):
#my others code....
if user is not None and account_activation_token.check_token(user, token):
profile_obj = UserProfile.objects.filter(user=user).update(email_confirmed = True)
messages.success(request, ('Your account have been confirmed. Now you can login'))
return redirect('members:change-password-page')
else:
messages.warning(request, ('The confirmation link was invalid, possibly because it has already been used.'))
return redirect('members:change-password-page')
#my others code....
解决方案
推荐阅读
- java - 如何为我的 HTTP GET 方法的 URL 设置变量端点?
- arrays - 具有唯一元素的 np 数组行
- xamarin.android - 一个小图像在 ImageView 中拉伸,其尺寸大于主图像
- python - 使用 Pandas 中的查询从 SQL 表中删除记录
- python - 读取文件并尝试补全数据库中缺失的信息
- python - 在嵌套理解中使用海象运算符 := 的替代方法
- arrays - 如何使用 Json Extractor 从 Jmeter 中的嵌套 Json 中提取数据
- python - 如何在python中将平面列表转换为字典?
- amazon-web-services - 有没有办法在 AWS 内部路由网络流量?
- wmi - 在 UEFI 中实现 ACPI 功能