【发布时间】:2019-11-14 11:12:17
【问题描述】:
Django 文档中有以下 ReportLab 示例。
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
但是。我想使用 RML 来生成我的 PDF。 ReportLab Plus 提供了一个rml2pdf 函数,可以使用与 Django 模板类似的标记将 RML 文档转换为 PDF。如何向 Django 提供 RML 模板并让 Django 在 API 响应中返回 PDF,类似于文档中的示例?
【问题讨论】:
标签: django-rest-framework reportlab rml