Django处理前端上传的文件

file = request.FILES.get('img')获取文件对象file
file.name可以获取文件名

file = request.FILES.get('img')
with open('static/img/' + file.name, 'wb') as fp:
    for chunk in file.chunks():
        fp.write(chunk)

你可能感兴趣的:(python,django)