Ten kod zwraca plik .pdf jako odpowiedź w przeglądarce. A jak zapisać plik w folderze media na serwerze? powie mi ktoś?
# Create a file-like buffer to receive PDF data.
buffer = io.BytesIO()
# Create the PDF object, using the buffer as its "file."
p = canvas.Canvas(buffer)
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full list of functionality.
p.drawString(30, 800, 'invoice num: ' + request.data['invoice_num'])
p.drawString(30, 750, 'issuer: ' + request.data['issuer'])
p.drawString(30, 700, 'header: ' + request.data['header'])
p.drawString(30, 650, 'notes: ' + request.data['notes'])
# Close the PDF object cleanly, and we're done.
p.showPage()
p.save()
# FileResponse sets the Content-Disposition header so that browsers
# present the option to save the file.
buffer.seek(0)
return FileResponse(buffer, as_attachment=True, filename=serializer.data['invoice_num'] + '.pdf')