Django利用Ajax提交文件到后台




   
   
   


    




   

       

       

       
   

    XMLRequest按钮上传
    XMLRequest按钮上传

   



后台代码:


def upload(request):
    if request.method=="POST":
        user=request.POST.get("user",None)
        img=request.FILES.get("imgg",None)
        from django.core.files.uploadedfile import TemporaryUploadedFile
        print(img._get_name(),type(img))
        f=open(os.path.join("statics",img.name),"wb")
        for chunck in img.chunks():
            f.write(chunck)
        f.close()
        return HttpResponse("ok")
    return  render(request,"upload.html")


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