我正在创建一个网站,我可以上传一个下载页面上的目录,用户可以下载它们,我可以通过在视图中使用以下代码为单个文件实现这一点,但我需要一个更简单的方法,我可以在管理或模板上做到这一点。你知道吗
def brochure(request):
fs = FileSystemStorage()
filename = 'kastom_profile.pdf'
if fs.exists(filename):
with fs.open(filename) as pdf:
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'inline;filename="kastom_profile.pdf"'
return response
else:
return HttpResponseNotFound('The requested pdf was not found in our server.')
目前没有回答
相关问题 更多 >
编程相关推荐