这是我的看法:
from django.conf import settings
from django.http import HttpResponse
from django.template.loader import render_to_string
import weasyprint
@staff_member_required
def admin_order_pdf(request, order_id):
order = get_object_or_404(Order, id=order_id)
html = render_to_string('orders/order/pdf.html', {'order': order})
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)时,它给了我一个错误。
ERROR:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/orders/order/
Django Version: 1.8.6
Exception Type: OSError
Exception Value:
dlopen() failed to load a library: cairo / cairo-2
我已经安装了weasyprint和cairocffi。我正在使用osx El Capitan。
最佳答案
通过在Ubuntu上安装以下依赖项为我解决了此问题:
sudo apt-get install libpango1.0-0
sudo apt-get install libcairo2
sudo apt-get install libpq-dev
在链接中检查依赖项:
http://weasyprint.readthedocs.io/en/latest/install.html
关于django - dlopen()无法加载库:cairo/cairo-2,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37437041/