1

我正在从 Angular 向 Django 发送一个 excel 文件。我想使用 Pandas 读取文件并在文件中执行一些操作,但我不知道该怎么做。

class fileupload(APIView) :
    def post(self, request): 
        f = request.FILES
        print(f)

当我打印时,它显示在下面,

<MultiValueDict: {'excelfile': [<InMemoryUploadedFile: New_Excel.xlsx (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)>]}>

在这里,我想将此文件保存到某个位置并使用 pandas 执行操作,或者如果可能的话,直接需要使用 pandas 读取文件。我是 Django 和 Pandas 的新手,所以如果有什么问题,请帮忙.. 提前致谢

4

2 回答 2

2
from django.core.files.storage import default_storage    
from django.core.files.base import ContentFile
file_objs = request.data.getlist('files')
for file_obj in file_objs:
    path = default_storage.save(settings.MEDIA_ROOT, ContentFile(file_obj.read()))
    print("images path are",path)
于 2020-05-17T15:31:56.967 回答
0
class fileupload(APIView) :
def post(self, request): 
    f = request.data.getlist("excelfile")
    print(f) # list of elements

现在循环 f 然后一个一个存储

于 2019-12-26T15:30:44.463 回答