Skip to content

Instantly share code, notes, and snippets.

@vgk77
Created March 15, 2020 15:13
Show Gist options
  • Select an option

  • Save vgk77/31e2a270908c7d21f525fb7850520595 to your computer and use it in GitHub Desktop.

Select an option

Save vgk77/31e2a270908c7d21f525fb7850520595 to your computer and use it in GitHub Desktop.
#python generate pdf
def get_pdf_contract(context_data):
html_string = render_to_string("mobile/loan_terms.html", context_data)
html = HTML(string=html_string)
contract_file = BytesIO(html.write_pdf())
print(contract_file)
html.write_pdf(target='/tmp/loan.pdf');
fs = FileSystemStorage('/tmp')
with fs.open('loan.pdf') as pdf:
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="loan.pdf"'
return response
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment