python- 初步认识 上传文件
作者:互联网
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')
标签:文件,obj,render,python,list,request,初步,file,上传 来源: https://www.cnblogs.com/longly1111/p/16157027.html