def file_download(request, pk, *args):
file = get_object_or_404(File, pk=pk)
if getattr(settings, "USE_X_ACCEL_REDIRECT", False):
response = HttpResponse()
response["X-Accel-Redirect"] = file.file.url
# delete content-type to allow Gondor to determine the filetype and
# we definitely don't want Django's default :-)
del response["content-type"]
else:
response = static.serve(request, file.file.name, document_root=settings.MEDIA_ROOT)
return response
评论列表
文章目录