[英]Cannot response a pdf file in circus
我已經完成了實現pdf打印功能。 我使用pyramid , wkhtmltopdf和jinja2生成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但circusd失敗
嘗試設置content_length
。 您正在使用的WSGI服務器可能不支持流響應(如果您使用.write()
或.app_iter
而未設置content_length
,則可能會發生這種情況)。 對於您的用例,您很可能會很高興只是設置可以照顧您一切的body
。
response.body = pdf_renderer(html)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.