我的观点
@api_view(['GET'])
@renderer_classes((JSONRenderer,TemplateHTMLRenderer,BrowsableAPIRenderer))
def admin_order_pdf(request, order_id):
# def admin_order_pdf(request, order_id):
order = get_object_or_404(Direct, id=order_id)
price=order.price
discount=order.discount
total=price-discount
html = render_to_string('bill/bill.html',
{'order': order,'total':total})
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'filename=\
"order_{}.pdf"'.format(order.id)
weasyprint.HTML(string=html).write_pdf(response,
stylesheets=[weasyprint.CSS(
settings.STATIC_ROOT + 'css/pdf.css')])
return response当我试图运行服务器或试图运行weasyprint代码时,我被一个错误激发为
raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names))
OSError: dlopen() failed to load a library: cairo / cairo-2 / cairo-gobject-2我也更新了环境变量。
C:\Program Files\GTK3-Runtime Win64\bin到这个地方
发布于 2019-03-06 14:04:39
确保安装了pixman (lib像素1-devel)、png、pango和poppler (PDF生成)的Cygwin开发库。要做到这一点,运行Cygwin安装程序,并寻找像素,波普尔和libpng,并安装的发展库。
我在为Pango安装开发库时注意到,它安装了Cairo和其他dep的特殊"GTK“版本。
一旦我安装了那些Cygwin库,一切正常工作,上面的错误消息就消失了(我还从源代码编译和安装了Pixman,这可能是修复的一部分,也可能不是修复的一部分)。
https://stackoverflow.com/questions/53727760
复制相似问题