wkhtmltopdf-django动态模板渲染
有什么方法可以动态生成PDF,并且内容从数据库中获取?
我的目标是允许用户从Wysiwyg编辑器中生成自己的PDF设计。
这是我的模型
class DocumentService(models.Model):
name = models.CharField(max_length=60, blank=True)
html_content = models.TextField(blank=True)
,我使用django-wkhtmltopdf将HTML渲染为PDF。
response = PDFTemplateResponse(
request=request,
template="document.html",
filename=filename,
context=data,
show_content_in_browser=True,
cmd_options=cmd_options,
)
如何将此记录的内容渲染到我的PDF中?
document = DocumentService.objects.get(pk=1)
document.html_content # <-- this content
HTML内容应该是这样的
<html>
<body>
<p>
<strong>Date: </strong> {{date}}
<strong>User: </strong> {{user.name}}
<strong>Email: </strong> {{user.email}}
<strong>Info: </strong> {{user.info}}
...
</p>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用
以及您的 document.html
Just use
engines.from_string(template_code)
and inside your document.html you've to add like this