【发布时间】:2023-03-03 07:51:23
【问题描述】:
我正在尝试将 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
命令:
wkhtmltopdf http://www.google.com output.pdf
在终端上完美运行 我使用这个指南来部署 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")
【问题讨论】:
标签: django nginx uwsgi wkhtmltopdf