我的观点
@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
到这个位置