关于使用 django 中的报告实验室生成的 pdf,我有 3 个问题,我似乎无法找到一个好的答案。django 站点上的文档仅涵盖如何生成 pdf 以供下载。但是如何将生成的 pdf 附加到电子邮件中并发送而不是下载呢?如何将 pdf 保存到服务器上的目录而不是下载它?如何在浏览器窗口中显示 pdf 而不是下载它?只需使用 django 文档示例:
from reportlab.pdfgen import canvas
from django.http import HttpResponse
def some_view(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
# Create the PDF object, using the response object as its "file."
p = canvas.Canvas(response)
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full list of functionality.
p.drawString(100, 100, "Hello world.")
# Close the PDF object cleanly, and we're done.
p.showPage()
p.save()
return response