本文整理匯總了Python中models.Document.select_file方法的典型用法代碼示例。如果您正苦於以下問題:Python Document.select_file方法的具體用法?Python Document.select_file怎麽用?Python Document.select_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Document
的用法示例。
在下文中一共展示了Document.select_file方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle_download
# 需要導入模塊: from models import Document [as 別名]
# 或者: from models.Document import select_file [as 別名]
def handle_download(request, uid, fname):
"""
Serves requested file as a download attachment
"""
doc = Document.select_file(uid, fname)
fpath = settings.BASE_DIR + doc.doc_file.url
if not doc or not os.path.exists(fpath):
return error_response(['Requested file \'{}\' not found'.format(fname)])
with open(fpath, 'r') as file:
data = file.read()
response = HttpResponse(data, content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="{}"'.format(fname)
return response