文件上传

文件上传 -- 初版

视图函数

def upload(request):
    if request.method == "GET":
        return render(request,'upload.html',locals())
    elif request.method == "POST":
        user = request.POST.get('user')
        obj = request.FILES.get('file')
        # f = open(obj.name, 'wb')
        f = open(os.path.join('upload',obj.name),'wb')
        for chunk in obj.chunks():
            f.write(chunk)
        f.close()
        return render(request,'upload.html',locals())

模板




    
    upload


你可能感兴趣的:(文件上传)