[英]Updating an existing user's profile is creating a new user in Django connected with MongoDB
我寫了這個 function 來更新現有用戶的個人資料,但它正在創建一個新用戶而不是更新現有用戶。 請你幫忙找出問題所在。
這是我的更新邏輯
def update_Profile(request):
if request.method == 'POST':
address =request.POST['address']
country=request.POST['country']
city=request.POST['city']
zipcode =request.POST['zipcode']
dob=request.POST['dob']
gender =request.POST['gender']
weight =request.POST['weight']
height =request.POST['height']
if(request.session.has_key('user_id')):
userid = request.session['user_id']
if User_profile.objects.filter(email = userid).exists():
user = User_profile.objects.create(address = address ,city=city,country=country,zipcode=zipcode,dob=dob,gender=gender,weight=weight,height=height)
user.save()
return render(request,'app/userProfile.html')
else:
print ('login first')
else:
return render(request,'app/login.html')
else:
return render(request,'app/login.html')
謝謝您的幫助。
您可能需要使用更新而不是假設 email 真的等於用戶 ID
User_profile.objects.filter(email = userid).update(
address=address,
city=city,
country=country,
zipcode=zipcode,
dob=dob,
gender=gender,
weight=weight,
height=height
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.