Siv*_*lam 4 python django xhtml2pdf
截至目前,我们正在使用XHTML2PDF动态生成PDF并在需要时输出到浏览器.现在我们的要求已更改为仅生成一次PDF并将其存储在服务器中.应该向用户显示该链接以查看PDF.你能指出任何资源或片段来达到这个目的吗?
这很容易做到.注意:
from django.core.files.base import ContentFile
# get_pdf_contents should return the binary information for
# a properly formed pdf doc.
pdf_contents = get_pdf_contents()
file_to_be_saved = ContentFile(pdf_contents)
item = Item.objects.get(pk=1)
item.myfilefield.save('blarg.pdf', file_to_be_saved)
Run Code Online (Sandbox Code Playgroud)
get_pdf_contents函数不应该太难写 - 基本上采用你已经拥有的任何函数并在将结果汇总到HttpResponse对象之前将其删除.如果您需要帮助,请发布您已经拥有的代码.