django中文件上传

前端

后端

def upload(request):
    if request.method == 'POST':
        file_obj = request.FILES.get('myfile')
        file_name = file_obj.name
        with open(file_name, 'wb') as f:
            # for line in file_obj:
            for line in file_obj:
                f.write(line)

    return render(request, 'upload.html')

你可能感兴趣的:(django)