def download_once(request, ref_key=None):
cache_key = 'document-ref-{}'.format(ref_key)
doc_id = cache.get(cache_key)
if not doc_id:
raise Http404()
cache.delete(cache_key)
doc = get_object_or_404(Document, pk=doc_id)
response = FileResponse(doc.retrieve(request.user, 'view'),
content_type=doc.mimetype)
# Disable browser caching, so the PDF won't end up on the users hard disk.
response['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response['Pragma'] = 'no-cache'
response['Expires'] = '0'
response['Vary'] = '*'
return response
评论列表
文章目录