Django pdf 问题与 pisa
我想使用 pisa 生成 pdf 文件的 html 模板。我相信我拥有所需的所有软件包,但我似乎在这样做时遇到了问题。这是我的观点如下 到目前为止我所做的一切。
编辑:这是我最新的网址、视图和内容。模板。
url.py
(r'^index/render_pdf/(?P<id>\d+)/$', render_pdf),
views.py
def fetch_resources(uri, rel):
path = os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, ""))
return path
def render_pdf (html, id):
invoice_items_list = Invoice_Items.objects.filter(pk=id)
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), dest=result, link_callback=fetch_resources)
return result
在模板中,我有这个标签。
<a href="{% url c2duo.views.render_pdf invoices.pk %}">
I want to generate a html template to a pdf file using pisa. I believe I have all the packages I need but I seem to be having problems doing so. Here is my view below so
far what I have done.
EDIT: Here is my latest url, views & template.
url.py
(r'^index/render_pdf/(?P<id>\d+)/
views.py
def fetch_resources(uri, rel):
path = os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, ""))
return path
def render_pdf (html, id):
invoice_items_list = Invoice_Items.objects.filter(pk=id)
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), dest=result, link_callback=fetch_resources)
return result
In a template, I have this tag.
<a href="{% url c2duo.views.render_pdf invoices.pk %}">
, render_pdf),
views.py
In a template, I have this tag.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道这有多大帮助,但这是我用来渲染 pdf 的函数:
I dont know how much this will help, but this is the function i use to render the pdf:
只是为了好玩,请尝试以下操作:
如果您仍然遇到错误,我猜测错误可能出在比萨中。您确定它是最新的吗?
Just for fun, try this instead:
If you still encounter an error, I'm guessing the error might be in pisa. Are you sure it's up to date?