【发布时间】:2021-11-27 14:35:25
【问题描述】:
我想在 django 中提供受保护的内容,所以我尝试在 django 和 apache 中设置 xsendfile。它适用于 ascii 文件名,但是当我尝试使用非 ascii 文件名时,apache 服务器以 404 响应。有人知道这里发生了什么吗?
Django:
def media_xsendfile_pdf(request):
file = Media.objects.last()
response = HttpResponse()
response['Content-Type'] = 'application/pdf'
response['X-Sendfile']= smart_str(f"{settings.BASE_DIR}{file.file.url}")
return response
Apache:
AllowEncodedSlashes On
XSendFile On
XsendFilePath /path-to-the-protected-resource
【问题讨论】:
标签: python python-3.x django django-views x-sendfile