一、文件上传
Views.py
def upload(request):
if request.method == "POST": # 请求方法为POST时,进行处理
myFile = request.FILES.get("myfile", None) # 获取上传的文件,如果没有文件,则默认为None
if not myFile:
return HttpResponse("no files for upload!")
# destination=open(os.path.join('upload',myFile.name),'wb+')
destination = open(
os.path.join("你的文件存放地址", myFile.name),
'wb+') # 打开特定的文件进行二进制的写操作
for chunk in myFile.chunks(): # 分块写入文件
destination.write(chunk)
destination.close()
return HttpResponse("upload over!")
else:
file_list = []
files = os.listdir('D:\python\Salary management system\django\managementsystem\\file')
for i in files:
file_list.append(i)
return render(request, 'uploa