File update

django file updates:

Be sure to put the final update file, otherwise the file will be lost!

Reference https://blog.csdn.net/weixin_33127753/article/details/88227832

from django.core.files.base import ContentFile

 

= request.FILES.get File ( "Wenjian", None) 
IF not File:
( "! No files") return HttpResponse
IF File:
BookInfo.objects.filter (the above mentioned id = 9) .Update (** real_dict)


obj = BookInfo .objects.filter (id = 9) .first ( ) # obtain an instance of the object class corresponding to
file_content = ContentFile (file.read ()) # Create Object ContentFile
obj.wenjian.save (file.name, FILE_CONTENT)
obj.save ()

 

 

 

Guess you like

Origin www.cnblogs.com/realadmin/p/11955165.html