I installed the package weasyprint according to the instructions Installing weasyprint (Django project).
My system: win 10. I have installed gtk3 and it is present in my PATH
import weasyprint
...
@staff_member_required
def order_admin_pdf(request, order_id):
# Получаем заказ по ID:
order = get_object_or_404(Order, id=order_id)
# Передаем объект в функцию render_to через генерацию шаблона pdf.html HTML в виде строки:
html = render_to_string('shop/orders/order_admin_pdf.html',
{'order': order})
# Создаем объект овтета с типом содержимого application/pdf и заголовком Content-Disposition:
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'filename=order_{}.pdf"'.format(order.id)
# Вызов метода weasyprint для получения PDF документа:
weasyprint.HTML(string=html).write_pdf(response,
stylesheets=[weasyprint.CSS(
settings.STATIC_ROOT + 'css/pdf.css')])
return response
OSError: cannot load library 'gobject-2.0': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0'