Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. statistics_string = render_to_string('statistics/statistics_pdf.html', context)
  2. html = HTML(string=statistics_string, base_url=request.build_absolute_uri()) html.write_pdf(target='/tmp/statistics.pdf', stylesheets=[CSS(STATIC_ROOT+'/css/index-style.css')])
  3. fs = FileSystemStorage('/tmp')
  4. with fs.open('statistics.pdf') as pdf:
  5.     response = HttpResponse(pdf, content_type='application/pdf')
  6.     response['Content-Disposition'] = 'attachment; filename="statistics.pdf"'
  7.      
  8. return response
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement