小编kft*_*ftb的帖子

Django 在 PDF 导出中更改文件名

我在Django Docs 中找到了这个方便的代码:

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, …
Run Code Online (Sandbox Code Playgroud)

python pdf django

1
推荐指数
1
解决办法
1680
查看次数

标签 统计

django ×1

pdf ×1

python ×1