Python Docraptor API Django获取PDF下载

Python Docraptor API Django获取PDF下载,python,django,pdf,Python,Django,Pdf,我试图在Django 2.0和Python 3中使用Docraptor 我可以将PDF生成到他们的网站,但不能下载到我的系统 这是他们的代码 下载pdf文件需要更改哪些内容 doc_api = docraptor.DocApi() try: create_response = doc_api.create_doc({ "test": True, "document_content": "<html><body>Hello World&

我试图在Django 2.0和Python 3中使用Docraptor

我可以将PDF生成到他们的网站,但不能下载到我的系统

这是他们的代码

下载pdf文件需要更改哪些内容

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)
doc\u api=docraptor.DocApi()
尝试:
create\u response=doc\u api.create\u doc({
“测试”:正确,
“文档内容”:“你好,世界”,
“名称”:“docraptor python.pdf”,
“文件类型”:“pdf”,
})
file=open(“/tmp/docraptor python.pdf”、“wb”)
file.write(创建\u响应)
file.close()文件
打印(“将PDF文件写入/tmp/docraptor python.PDF”)
除了docraptor.rest.ApiException作为错误外:
打印(错误)
打印(错误消息)
打印(错误代码)
打印(错误。响应\u正文)
我猜有某种HttpResponse丢失了

一旦我解决了这个问题,这似乎是一个生成PDF文件的好方法。他们的技术支持很棒,但文档有点短


谢谢。

是的,缺少响应。一般来说是这样的:

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

是的,缺少响应。一般来说是这样的:

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