[Fixed]-Adding generated PDF to FileField fails; adding local PDF works

1👍

✅

File() is only a wrapper around Python’s file object. It won’t work with strings like your generated PDF. For that, you need the ContentFile class. Try:

(...)
djangofile = ContentFile(pdf_file)
invoice.pdf = djangofile
invoice.pdf.name = "myfilename.pdf"
invoice.save()

Leave a comment