一个从模板生成PDF的Django应用程序
项目描述
注意
这是https://github.com/xhtml2pdf/django-xhtml2pdf项目的分支。
该项目是django项目和xhtml2pdf项目之间的包装代码,两者都有一些维护,可能不适合您的项目。
它所做的是简单地允许人们使用所有酷炫的django功能(如STATIC_URL等)创建xhtml2pdf模板(就像网页模板一样),而utils函数则使所有图像和资源都显示在PDF中。
此版本(0.0.7)支持Django 2.0和Python 3.6。
注意
虽然本项目在有限程度上维护了旧项目,但我们强烈建议新项目考虑使用WeasyPrint <https://weasyprint.org>。
用法
只需执行以下操作
from django_xhtml2pdf.utils import generate_pdf def myview(response): resp = HttpResponse(content_type='application/pdf') result = generate_pdf('my_template.html', file_object=resp) return result
基于类的视图
您可以使用提供的PdfMixin与任何子类化TemplateView的视图一起使用,例如
from django.views.generic.detail import DetailView from django_xhtml2pdf.views import PdfMixin from .models import Product class ProductPdfView(PdfMixin, DetailView): model = Product template_name = "product_pdf.html"
它将以PDF的形式输出视图的渲染内容。
装饰器
只需执行以下操作
from django_xhtml2pdf.utils import pdf_decorator @pdf_decorator def myview(request): return render(request, 'mytemplate.html')
更改PDF文件名
from django_xhtml2pdf.utils import pdf_decorator @pdf_decorator(pdfname='new_filename.pdf') def myview(request): return render(request, 'mytemplate.html')
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。
源代码发行版
lanshark-django-xhtml2pdf-0.0.7.tar.gz (45.3 kB 查看哈希值)
构建发行版
关闭
lanshark-django-xhtml2pdf-0.0.7.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3954fc1bb454aef1b4430d9dbbdb71476e8ea17aa7f0c41faf6cf7405ec7dd15 |
|
MD5 | 6220bbad4c80a5a316132bad4c71c91c |
|
BLAKE2b-256 | 96906b70c4cbd0d19aaacad91d3f6fc94bfeb33840f8617b8c1bd9169d7c14bc |
关闭
lanshark_django_xhtml2pdf-0.0.7-py2.py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 1d4a3bb1a2286bb4fc5d79f3fece4d89d5e2064dff663d53982c988afe4a67cb |
|
MD5 | e0f6d9242610ceecacc591b8dcdd6923 |
|
BLAKE2b-256 | 644edbf069c25119c1019ebbc564ebd8afef1c0cca970722b2946987a0f76b9f |