我使用pdfkit和wkhtmltopdf来生成PDF文档。第一次生成PDF时一切正常。如果我在5秒内快速生成另一个PDF,就会出现错误[Errno 9] Bad file descriptor。如果我关闭错误(在浏览器中返回)并重新打开,它将创建PDF。
我的views.py文件:
重要提示:我在IIS8上运行此站点,当从命令行运行(python manage.py runserver)时,错误不存在。
如何处理此错误的任何指南都将是很好的帮助。
我的views.py文件:
config = pdfkit.configuration(wkhtmltopdf='C:/wkhtmltopdf/bin/wkhtmltopdf.exe')
pdfgen = pdfkit.from_url(url, printname, configuration=config)
pdf = open(printname, 'rb')
response = HttpResponse(pdf.read())
response['Content-Type'] = 'application/pdf'
response['Content-disposition'] = 'attachment ; filename =' + filename
pdf.close()
return response
重要提示:我在IIS8上运行此站点,当从命令行运行(python manage.py runserver)时,错误不存在。
如何处理此错误的任何指南都将是很好的帮助。
printname
是从哪里来的? - Kevin Christopher Henry