1. 静态文件
<div class="form-group"> <label for="exampleInputFile">上传文件</label> <input type="file" name="file"> </div>
2. views.py
from django.shortcuts import render,HttpResponse def upload_list(request): if request.method == 'GET': return render(request, 'upload_list.html') #获取文件 file_obj = request.FILES.get('file') # 写入文件 f = open(file_obj.name, mode='wb') for chunk in file_obj.chunks(): f.write(chunk) f.close() return HttpResponse('111')