<form method='post' enctype='multipart/form-data'>
<input type='file' name='filename' >
def upload_file(request):
if request.method=="POST":
? ? file = request.FILES.get("filename")
? ? with open('/ss/s/s/s+'filename'','wb') as save_file:
? ? for part in filename.chunks():
? ? ? ? save_file.write(part)
? ? ????save_file.flush()
-----------------------------------------------------------------------------
或者使用Django封裝
class supermodel(models,Model):
? ? u_icon=models.ImageField(upload_to='icons') (需要使用pillow 包)
? ? 添加Media root
MEDIA_ROOT=os.path.join(BASE_DIR,)
? ? --------------------------------------------------------------------------------