python3 django 下载文件

    def download_file(self, request, *args, **kwargs):
    
        path = r'C:\Users\Administrator\Desktop\test.txt'
        file = open(path, 'rb')
    
        response = FileResponse(file)
        response['Content-Type'] = 'application/octet-stream'
        filename=quote('test.txt'.encode('utf-8'))
        response['Content-Disposition'] = 'attachment;filename="text.txt"'
    
        return response

 

你可能感兴趣的:(web)