Это решение для моего случая, в котором я использую django 2.0.1 и pdfkit 0.6.1:
. Чтобы получить шаблон:
template = get_template ('plapp / person_list.html')
Чтобы отобразить его с данными:
html = template.render ({'persons': persons})
Для продолжения определения метода в views.py, тот, который загружает PDF непосредственно в браузер:
def pdf(request):
persons = Person.objects.all()
template = get_template('plapp/person_list.html')
html = template.render({'persons': persons})
options = {
'page-size': 'Letter',
'encoding': "UTF-8",
}
pdf = pdfkit.from_string(html, False, options)
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'attachment;
filename="pperson_list_pdf.pdf"'
return response