Django api接收csv文件

我是django的新手,我想构建一个接受csv文件并对其进行解析的django视图。

@permission_classes([AllowAny])
class FileUploadView(views.APIView):
    parser_classes = (MultiPartParser,)

    def post(self,request,format=None):
        print(request.data)
        return JsonResponse({'message': 'good !'},status=202)

问题是当我查询此api时出现错误。

这是我的查询方式:

with open('dispatch.csv','rb') as f:
    res = requests.post("http://127.0.0.1:8000/api/mds/generate_from_csv/",data={'file': f},headers={"Content-Type": "multipart/form-data"})
    print(res.raise_for_status())

这是我收到的错误消息:

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://127.0.0.1:8000/****
lnnyynv81 回答:Django api接收csv文件

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3116566.html

大家都在问