文件更新

django 文件更新:

文件更新一定要放到最后,否则文件会丢失!

参考https://blog.csdn.net/weixin_33127753/article/details/88227832

from django.core.files.base import ContentFile

 

file = request.FILES.get("wenjian", None)
if not file:
return HttpResponse("没有文件!")
if file:
BookInfo.objects.filter(id=9).update(**real_dict)


obj = BookInfo.objects.filter(id=9).first() # 获取对应类的实例化对象
file_content = ContentFile(file.read()) # 创建ContentFile对象
obj.wenjian.save(file.name,file_content)
obj.save()

 

 

 

posted @ 2019-11-29 01:14  real-admin  阅读(268)  评论(0编辑  收藏  举报