我正在尝试将 wkhtmltopdf 与 Django 、nginx、uwsgi 一起使用,它在使用 manage.py runserver 运行的开发环境中完美运行,但是当与 nginx ans uwsgi 一起使用时,我收到此错误:
wkhtmltopdf exited with non-zero code 1. error:
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-isp'
qt.qpa.screen: QXcbConnection: Could not connect to display
Could not connect to any X display.
Exception Location: /home/isp/Env/isp/lib/python3.6/site-package/pdfkit/pdfkit.py in to_pdf, line 159
Run Code Online (Sandbox Code Playgroud)
命令 :
wkhtmltopdf http://www.google.com output.pdf
Run Code Online (Sandbox Code Playgroud)
在终端上完美运行,我使用这个 guid 来部署 Django 应用程序 https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu- 16-04#setting-up-the-uwsgi-application-server
我认为它与 virtualenv 有关,我尝试使用这个包装器 https://github.com/JazzCore/python-pdfkit/wiki/Using-wkhtmltopdf-without-X-server
但仍然有同样的错误
我的代码:
import pdfkit
pdfkit.from_file("./invoices/invoice"+str(booking_id)+"-"+str(invoice_id)+".html", "invoices/invoice_initial"+str(booking_id)+"-"+str(invoice_id)+".pdf")
Run Code Online (Sandbox Code Playgroud)