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)
# content_type='application/octet-stream',指明下载类型
————————————————
版权声明:本文为CSDN博主「正牌小白牙」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_41678663/article/details/85015365