该
QuerySet.update()方法不会调用
save()模型,因此不会执行将图像放入存储区的常规机制。另外,您必须从
request.FILESnot检索上传的图像
request.POST。
update()如果您在模型实例上设置属性然后调用
save(),而不是使用,则应该将映像保存到磁盘上的正确位置。例如:
profile_pic = request.FILES.get('profile_pic') # Use request.FILESbio = request.POST.get('bio')city = request.POST.get('city')dob = request.POST.get('dob')gender = request.POST.get('gender')user_profile = Profile.objects.get(user=request.user)user_profile.bio = biouser_profile.city = cityuser_profile.date_of_birth = dobuser_profile.profile_pic = profile_picuser_profile.gender = genderuser_profile.save()如评论中所述,还必须确保已
enctype="multipart/form-data"设置表单。



