【发布时间】:2019-03-29 17:21:14
【问题描述】:
我正在做有关 DRF+Angular 的项目。目前在本地主机上,我可以下载带有操作的文件:
@action(methods=['get'], detail=True)
def download(self, *args, **kwargs):
instance = self.get_object()
file_handle = instance.file.open()
response = FileResponse(file_handle.read(), content_type='application/file')
response['Content-Length'] = instance.file.size
response['Content-Disposition'] = f'attachment; filename="{instance.file.name}"'
file_handle.close()
return response
它适用于 localhost,但是当前端尝试在服务器上的相同 url 下获取相同的文件时 - 我会重定向到带有 HTTP 401 Unauthorized 的 DRF 模板。但我已经输入了我的凭据。出了什么问题?
【问题讨论】:
-
你解决了吗?
标签: python django angular django-rest-framework