Trying to build a simple Weasy Print Application with Django
Made a little function at views.py:
def generate_pdf(request):
# Model data
students = Student.objects.all().order_by('last_name')
context = {
'invoice_id': 18001,
'street_name': 'Rue 76',
'postal_code': '3100',
'city': 'Washington',
'customer_name': 'John Cooper',
'customer_mail': 'customer@customer.at',
'amount': 1339.99,
'today': 'Today',
}
# Rendered
html_string = render_to_string('pdf/invoice.html', context)
html = HTML(string=html_string)
result = html.write_pdf()
# Creating http response
response = HttpResponse(content_type='application/pdf;')
response['Content-Disposition'] = 'inline; filename=list_people.pdf'
response['Content-Transfer-Encoding'] = 'binary'
with tempfile.NamedTemporaryFile(delete=True) as output:
output.write(result)
output.flush()
output = open(output.name, 'r')
response.write(output.read())
return response
After running it I get a UnicodeDecodeError for the line "response.write(output.read())" This is my first time having such a problem, how can I fix that? Thanks!