Write the upload file code today, as follows
def Uploadhandle (Request): pic1=request. files['pic1' picname=os.path.join (settings. Media_root,pic1.name) with open (Picname,'w') as Pic: for inch pic1.chunks (): pic.write (c) return HttpResponse (picname)
Appears typeerror:write () argument must is str, not bytes error
Online search only to find that the original file open method has a problem, the previous Open statement modified to open in binary mode is no problem
Switch
def Uploadhandle (Request): pic1=request. files['pic1' picname=os.path.join (settings. Media_root,pic1.name) with open (Picname,'wb+') as Pic: for inch pic1.chunks (): pic.write (c) return HttpResponse (picname)
The problem is caused by the fact that the pickle storage method is binary by default
Python read-write file Chinese garbled error typeerror:write () argument must be str, not bytes+