Created
March 15, 2020 15:13
-
-
Save vgk77/31e2a270908c7d21f525fb7850520595 to your computer and use it in GitHub Desktop.
#python generate pdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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