2017-12-23 7 views
0

나는 내가 PDF 자신의 웹 사이트에 생성하지만 내 시스템에 다운로드하지 얻을 수 장고 2.0 및 파이썬 3Docraptor API 장고는 PDF가

에 Docraptor를 사용하는 것을 시도하고 다운로드받을. 여기

는 pdf 파일을 다운로드 변경할 필요가 무엇 https://github.com/DocRaptor/docraptor-python

에서 자신의 코드?

doc_api = docraptor.DocApi() 

try: 

    create_response = doc_api.create_doc({ 
    "test": True,  
    "document_content": "<html><body>Hello World</body></html>", 
    "name": "docraptor-python.pdf", 
    "document_type": "pdf",  

    }) 
    file = open("/tmp/docraptor-python.pdf", "wb") 
    file.write(create_response) 
    file.close() 
    print("Wrote PDF to /tmp/docraptor-python.pdf") 

except docraptor.rest.ApiException as error: 
    print(error) 
    print(error.message) 
    print(error.code) 
    print(error.response_body) 

나는 어떤 종류의 HttpResponse가 누락 되었습니까?

이 문제를 극복 한 후에는 PDF 파일을 만드는 것이 좋습니다. 그들의 기술 지원은 훌륭하지만 문서가 조금 부족합니다.

감사합니다.

답변

2

예, 응답이 없습니다. 일반적으로 다음과 같습니다.

response = HttpResponse() 
response['Content-Type'] = 'application/pdf' 
response['Content-Disposition'] = 'attachment; filename="my_pdf.pdf"' 
response.write(creeate_response) 
return response 
+0

멋진데. 고마워요. – diogenes