1👍
✅
Just as an alterative approach try creating the response, then passing it directly to pisa?
response = http.HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=%s' % filename
pisa.CreatePDF(file_data, response)
return response
Have you decided against saving the file and serving it through Nginx X-Accel-Redirect? – Just for completeness here’s an example of that:
Django view:
resp = http.HttpResponse()
resp['Content-Type'] = 'application/pdf'
resp['Content-Disposition'] = 'attachment; filename=filename.pdf'
resp['X-Accel-Redirect'] = '/xaccel_path/%s' % relative_path_to_file
return resp
nginx config:
server {
...
location /xaccel_path {
internal;
alias /path/to/protected/files/;
}
}
Source:stackexchange.com