Преобразую HTML в PDF (Django) . Впервые такое делаю, выпадает ошибка
cannot import name 'getStringIO' from 'reportlab.lib.utils'
from django.shortcuts import render
from mes.models import News
import io
from io import BytesIO
from django.template.loader import get_template
from django.http import HttpResponse
from xhtml2pdf import pisa
def render_to_pdf(template_src, context_dict={}):
template = get_template(template_src)
html = template.render(context_dict)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), content_type="application/pdf")
return None
def contact_pdf(request):
pdf = render_to_pdf('pdf.html')
if pdf:
response = HttpResponse(pdf, content_type='application/pdf')
content = 'inline; filename=contact.pdf'
response['Content-Disposition'] = content
return response
Подскажите, в чем моя ошибка.