我正在尝试编写一个脚本,它将由 xhtml2pdf 创建的 pdf 直接保存到服务器,而不是按照通常的方式提示用户将其下载到他们的计算机上。Documents() 是我要保存到的模型,并且 new_project 和 output_filename 变量设置在其他地方。
html = render_to_string(template, RequestContext(request, context)).encode('utf8')
result = open(output_filename, "wb")
pdf = CreatePDF(src=html, dest=results, path = "", encoding = 'UTF-8', link_callback=link_callback) #link callback was originally set to link_callback, defined below
result.close()
if not pdf.err:
new_doc=Documents()
new_doc.project=new_project
new_doc.posted_by=old_mess[0].from_user_fk.username
new_doc.documents = result
new_doc.save()
使用此配置,当它到达 new_doc.save() 我得到错误:'file' object has no attribute '_committed'
有谁知道我该如何解决这个问题?谢谢!