how to render template with pdf file created by reportlab ?
class EmpresaReportView(BSModalFormView):
template_name = ‘report_form.html’
def get_success_url(self):
file = relatorio_empresa(self.request)
mytemplate = 'company/report_form.html'
return render(request, mytemplate, {'pdffile': file}) ??????????? file is a object pdf but does not work!
def relatorio_empresa(request):
response = HttpResponse(content_type=‘application/pdf’)
response[‘Content-Disposition’] = ‘inline; filename=“mypdf.pdf”’
buffer = io.BytesIO()
p = canvas.Canvas(buffer)
p.drawString(200, 810, 'Relatório de Funcionários')
p.drawString(0, 800, '_' * 150)
p.showPage()
p.save()
buffer.seek(io.SEEK_SET)
pdf = buffer.getvalue()
response.write(pdf)
buffer.seek(io.SEEK_SET)
from django.http import FileResponse
response = FileResponse(buffer, as_attachment=False, filename='mypdf.pdf', content_type='application/pdf')
response.headers['Content-Disposition'] = 'inline; filename= "mypdf.pdf"'
response.headers['Content-Type'] = 'application/pdf'
return response
template
<!doctype html>