【发布时间】:2020-02-04 18:00:26
【问题描述】:
pdfkit在本地机器上工作一切正常显示为pdf,但在digitalocean中向服务器发送错误500,为什么?
views.py
from django.shortcuts import render, redirect, get_object_or_404
from django.http import HttpResponse
from django.template.loader import get_template
import pdfkit
from .models import Buses
def pdf(request, id):
bus = Buses.objects.get(id=id)
template = get_template('buses/pdf.html')
html = template.render({'bus': bus})
options = {
'page-size': 'Letter',
'encoding': "UTF-8",
}
pdf = pdfkit.from_string(html, False, options)
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="{}_{}.pdf"'.format(bus.company, bus.name)
return response
【问题讨论】:
-
能否添加错误日志?
-
对于 PDF 生成,通常需要在 VM 上安装一些二进制文件。您是否安装了所有必需的依赖项?
-
@narendra-choudhary 我只安装 pip pdfkit
-
pdfkit 依赖于 wkhtmltopdf。你安装了 wkhtmltopdf 吗?来源:github.com/JazzCore/python-pdfkit
-
@narendra-choudhary 是的,我安装了 wkhtmltopdf,但是 pdfkit 不起作用?它发送到服务器错误 500
标签: django python-3.x pdfkit