前端
<div class="container">
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="text" name="username">
<input type="file" name="avatar">
<input type="submit" value="提交">
</form>
</div>
后端
def upload_list(request):
if request.method == 'GET':
return render(request, 'upload_list.html')
# print(request.POST) # 请求体中数据
# print(request.FILES) # 请求发过来的文件
file_object = request.FILES.get('avatar')
print(file_object.name)
f = open(file_object.name, mode='wb')
for chunk in file_object.chunks():
f.write(chunk)
f.close()
return HttpResponse('...')
标签:文件,list,chunk,object,request,file,print,上传
From: https://www.cnblogs.com/jyfyb/p/17834366.html