class DoView(APIView):
def get(self,request):
queryset = self.get_queryset()
serializer = self.get_serializer(queryset, many=True)
# 构造文件名
file_name = datetime.datetime.now().strftime('%Y%m%d%H%M%S') + ".json"
response = Response(serializer.data)
response["content_type"] = 'application/json'
response['Content-Disposition'] = "attachment; filename= {}".format(file_name)
return response
content_type='application/octet-stream',指明下载类型