При преобразовании HTML в pdf страница застревает на загрузке при создании pdf
При попытке сгенерировать файл pdf с помощью приведенного ниже кода браузер застрял при загрузке
from io import BytesIO
from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa
def render_to_pdf(template_src, context_dict={}):
template = get_template(template_src)
html = template.render(context_dict)
result = BytesIO()
print('RESULT')
pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
print('PDF')
if not pdf.err:
return HttpResponse(result.getvalue(), content_type='application/pdf')
return None
и generate_pdf view:
def generate_pdf(request):
pdf = render_to_pdf('doc.html', data)
response = HttpResponse(pdf, content_type='application/pdf')
filename = "Document_to_mail.pdf"
content = "inline; filename=%s" %(filename)
download = request.GET.get("download")
if download:
content = "attachment; filename=%s" %(filename)
response['Content-Disposition'] = content
return response
браузер застрял в pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)