При преобразовании HTML в pdf страница застревает на загрузке, пока я пытаюсь вернуть Http Response
При попытке вернуть именованный ответ с приведенным ниже кодом, чтобы сгенерировать файл pdf, браузер застрял при загрузке
def GeneratePdf(request, id):
job = Job.objects.get(pk=id)
products = Product.objects.all()
supplies = job.jobItem.all()
template_path = "company/jobDetails.html"
context = {
"job": job,
"status": status,
"supplies": supplies,
}
template = get_template(template_path)
html = template.render(context)
result = io.BytesIO()
#Creating the pdf
output = pisa.pisaDocument(io.BytesIO(html.encode("UTF-8")), result, encoding='UTF-8')
#output = pisa.CreatePDF(html, dest=response)
if not output.err:
pdf = HttpResponse(result.getvalue(), content_type='application/pdf')
pdf['Content-Disposition'] = 'filename="products_report.pdf"'
return pdf
Но при удалении части pdf['Content-Disposition'] = 'filename="products_report.pdf"'
, как в приведенном ниже коде, код работает и я получаю пронумерованный файл.
def GeneratePdf(request):
job = Job.objects.get(pk=id)
products = Product.objects.all()
supplies = job.jobItem.all()
template_path = "company/jobDetails.html"
context = {
"job": job,
"status": status,
"supplies": supplies,
}
template = get_template(template_path)
html = template.render(context)
result = io.BytesIO()
#Creating the pdf
output = pisa.pisaDocument(io.BytesIO(html.encode("UTF-8")), result, encoding='UTF-8')
#output = pisa.CreatePDF(html, dest=response)
if not output.err:
pdf = HttpResponse(result.getvalue(), content_type='application/pdf')
return pdf
Есть предложения?