Nyfregja
Nyfregja

Reputation: 11

Weasyprint gives Fontconfig error when used with Django

I'm trying to make an application that downloads a pdf report with data from a form. The form is done by Django, the pdf is by WeasyPrint. But they don't seem to work together.

This works fine as code outside of Django:

from `weasyprint` import HTML
HTML(string='test').write_pdf("./report.pdf")

However, when part of a Django response, like this:

def result(request):
    buffer = io.BytesIO()
    HTML(string='test').write_pdf(buffer)
    buffer.seek(0)
    return FileResponse(buffer, as_attachment=True, filename='report.pdf')

I get Fontconfig error: Cannot load default config file and my Django server closes. Any ideas on how to solve this? I'm on Windows 10, python 3.7, installed the latest versions of Django and WeasyPrint (and their dependencies) via conda.

Upvotes: 1

Views: 520

Answers (0)

Related Questions