Django上传文件之iframe

代码:




   
   
   
   


   
   




   


       

       

       
   

   





   



    XMLRequest按钮上传
    XMLRequest按钮上传

    测试Iframe

   




后端代码:

def upload(request):
    if request.method=="POST":
        ret={"status":True,"data":""}
        user=request.POST.get("user",None)
        img=request.FILES.get("img",None)
        from django.core.files.uploadedfile import TemporaryUploadedFile
        print(img._get_name(),type(img))
        print(img.size)
        f=open(os.path.join("static",img.name),"wb")
        ret["filepath"]=os.path.join("static",img.name)
        for chunck in img.chunks():
            f.write(chunck)
        f.close()
        return HttpResponse(json.dumps(ret))
    return  render(request,"upload.html")

你可能感兴趣的:(Python自动化开发)