[reportlab-users] Save PDF File to model using two views

Robin Becker robin at reportlab.com
Tue Jun 28 10:02:33 EDT 2011


On 28/06/2011 14:42, Asif Jamadar wrote:

> How can I save the dynamically generated PDF report into separate django model (database) as file.

>

>

>

> The below code works fine for me

>


Hi it looks to me as though analysis_report is producing a response into which
you have written a PDF. That is not the same as writing it into a StringIO
object. So in the first OK view you did

pdf = buffer.getvalue() #produces a stringof bytes
myfile = ContentFile(pdf)

in the second I see this sequence

pdf = buffer.getvalue()
response.write(pdf)
return response

.....

report = analysis_report(request) #ie the returned response
myfile = ContentFile(report) #not a string of bytes

and presumably the error happens here ie report is a response and not a string.

It may be better to factor out the pdf production bit from the analysis_report
function and use it directly.
--
Robin Becker


More information about the reportlab-users mailing list