我正在更新我的个人资料图片,图片已更新,之前的图片已从数据库中删除,但我想将其从文件夹中删除。
forms.py
def update(self, user):
#import pdb; pdb.set_trace()
data= self.cleaned_data
kuser = KUser.objects.filter(user=user)
if kuser:
kuser = kuser[0]
# delete file and update photo code here
if kuser.profile_image.image:
old_image = PHOTO_UPLOAD_DIR + kuser.profile_image.image.url
if os.path.exists(old_image):
os.remove(old_image)
os.remove(kuser.profile_image.image.url)
kuser.profile_image.image = data['image']
kuser.profile_image.save()
return kuser
图像在数据库中删除,但不在文件夹中删除。
拜托,谁能告诉你怎么做?