【发布时间】:2020-10-23 17:36:05
【问题描述】:
我对 Django 很陌生,我的项目要求我在点击链接时提示用户打开 pdf。我的本地机器上已经有 pdf 文件,不想使用 Reportlab 重新创建它。有什么办法吗?
我试过了
with open("/user/some/directory/somefilename.pdf") as pdf:
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
return response
但它返回 404 page not found 因为请求的 url 不在 myproject.urls 的 URLconf 中
我错过了什么?
【问题讨论】:
标签: django pdf-generation reportlab