1

我已经完成了打印pdf功能。我使用pyramidwkhtmltopdfjinja2来生成 pdf。它在gunicorn中运行良好。但是,当我将其部署到生产环境时(我使用circusd在生产环境中运行),该功能失败且没有任何错误消息。源代码如下:

pdf_renderer = PDFRenderer()

request = self.request

html = render('test.jinja2' , pdf_data, request)

response = request.response
response.write(pdf_renderer(html))
response.content_type = 'application/pdf'
response.headerlist.append(('Content-Disposition', 'attachment; filename='test.pdf'))

#Everything is ok except the final statement.
#circusd cannot run the statement "return response"
#However, gunicorn can do it
return response

那么,您对我的问题有什么建议或想法吗?它是如此直接,我无法理解为什么它在gunicorn中运行良好但在马戏团中失败

4

1 回答 1

1

Try setting the content_length. It's possible the WSGI server you are using does not support streaming responses (which would happen if you are using .write() or .app_iter without setting a content_length). For your use-case, it's more likely that you'd be happy just setting the body which would take care of everything for you.

response.body = pdf_renderer(html)
于 2013-05-03T08:26:13.637 回答