2014-07-22 2 views
0

xhtml2pdf로 만든 pdf를 사용자가 컴퓨터에 다운로드하라는 일반적인 경로를 따르지 않고 서버에 직접 저장하는 스크립트를 작성하려고합니다. . Documents()는 저장하려고하는 모델이고 new_project 및 output_filename 변수는 다른 곳에 설정됩니다. 이 new_doc.save에 도달이 구성장고 - 서버의 디스크에 xhtml2pdf로 만든 PDF를 작성하십시오.

  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() 

(I 오류 수) : '파일'개체가 어떤 속성이없는 '_committed을'

사람이 내가이 문제를 해결할 수있는 방법을 알고 있나요? 감사!

답변

2

해결 방법을 찾은 후에 해결 방법을 찾았습니다. 문제는 새 문서를 만들지 않고 결과 (pdf)가 아직 열려 있다는 것입니다.

"(+") open()에 "+"를 추가해야 pdf 파일을 쓰기 및 쓰기가 가능하도록 "+"추가해야했습니다.

먼저 다른 폴더 (pdf)에 pdf를 저장한다는 점에 유의하십시오. 응용 프로그램에서 원하는 결과가 아니라면 삭제해야합니다.

  html = render_to_string(template, RequestContext(request, context)).encode('utf8') 
      results = StringIO() 
      result = open("Files/"+output_filename, "w+b") 
      pdf = CreatePDF(src=html, dest=results, path = "", encoding = 'UTF-8', link_callback=link_callback) #link callback was originally set to link_callback, defined below 

      if not pdf.err: 
       result.write(results.getvalue()) 
       new_doc=Documents() 
       new_doc.project=new_project 
       new_doc.documents.save(output_filename, File(result)) 
       new_doc.posted_by=old_mess[0].from_user_fk.username 

       new_doc.save() 
      result.close() 
관련 문제