I have been unable to get my 'pdf downloader' to work from the pythonanywhere server. I can get it to work in my local development environment, but when I try it from the pythonanywhere server, at best I can get the file to save to the server itself. My project uses the Django framework with a front end written with Javascript. I am creating a PDF using reportLab (suggested in the Django docs for this sort of thing). I have tried a few different approaches including the suggested method from the Django docs found here: Django Response Object
My current code looks something like this:
def create_pdf(request):
data = json.loads(request.body)
invoice = get_invoice(data['iid'])
resp = HttpResponse(content_type='application/pdf')
resp['Content-Disposition'] = 'attachment; filename="sample.pdf"'
p = canvas.Canvas(resp)
#create the PDF file
p.save()
return resp
Anyone have experience doing something similar? Any help would be appreciated! Thanks~