文件上传
文件上传
上传与接收
def index(request):
if request.method == 'POST':
print(request.FILES) # 获取文件数据
file_obj = request.FILES.get('file') # 文件对象
print(file_obj)
with open(file_obj.name, 'wb') as f:
for line in file_obj: # 一行一行读取内容
f.write(line)
return render(request, 'index.html')

上传文件注意事项
1、必须是method='post'请求
2、enctype='multipart/form-data'


浙公网安备 33010602011771号