gpt4 book ai didi

django - wkhtmltopdf (pdfkit) 无法连接到任何 X 显示器

转载 作者:行者123 更新时间:2023-12-03 15:19:38 33 4
gpt4 key购买 nike

我正在尝试将 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

在终端上完美运行
我使用这个 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")

最佳答案

解决方案

而不是使用

apt-get install wkhtmltopdf

我从 releases page 下载了最新版本现在一切正常。

关于django - wkhtmltopdf (pdfkit) 无法连接到任何 X 显示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51787618/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com