【发布时间】:2018-07-21 18:56:39
【问题描述】:
类似的问题 django rest framework return file
尝试应用类似的解决方案在 Django Rest ApiView 中返回一个可执行的 python 二进制文件:
from wsgiref.util import FileWrapper
bin_file = open(f'cli/builds/dist/cli', 'rb')
response = Response(FileWrapper(bin_file), content_type='application/octet-stream')
response['Content-Disposition'] = f'attachment; filename="cli"'
response.status_code = status.HTTP_200_OK
return response
得到Object of type 'FileWrapper' is not JSON serializable 错误。
参考前面提到的 SO 主题 - 这个解决方案正在为一个 zip 文件工作。
问题 - 为什么它不适用于我的设置,返回 python 可执行文件?
python 3.6.5,
djangorestframework==3.8.2
尝试了Response 和HttpResponse 类
【问题讨论】:
标签: python django python-3.x django-rest-framework