Python-django-文件上传
1,后台
def upload(request): image = request.FILES.get('image') print(image.name) print(image.size) file = open(image.name, 'wb') for data in image.chunks(chunk_size=1024): file.write(data) return HttpResponse('successful')
2. 前端
<form action="" method="post" enctype="multipart/form-data"> {% csrf_token%} <input type="file" name="image"> <button type="submit">submit</button> </form>