librelist archives

« back to archive

NameError: global name 'send_file' is not defined

NameError: global name 'send_file' is not defined

From:
Michael Johnston
Date:
2012-07-19 @ 20:16
This one is driving me crazy. I'm using Flask 0.9 with an app that creates
thumbnail images on the fly.  At the end of the function, I'm using the 
following code, where localpath is the name of the image file. 

return send_file(localpath, mimetype="image/jpeg")

The Flask debugger kicks in with the error  "global name 'send_file' is 
not defined."

I'm sure this is because of something stupid. Would anyone care to 
publicly humiliate me with the solution?

Re: NameError: global name 'send_file' is not defined

From:
Michael Johnston
Date:
2012-07-19 @ 20:30
To save someone else the hassles of figuring this out, I'm going to answer
my own question..

Adding the following solved it:

from Flask import send_file

The docs didn't indicate this was necessary, which is why I didn't do it 
right off the bat. Or maybe it's because I'm a newbie at this.


On Thursday, July 19, 2012 at 4:16 PM, Michael Johnston wrote:

> This one is driving me crazy. I'm using Flask 0.9 with an app that 
creates thumbnail images on the fly.  At the end of the function, I'm 
using the following code, where localpath is the name of the image file. 
> 
> return send_file(localpath, mimetype="image/jpeg")
> 
> The Flask debugger kicks in with the error  "global name 'send_file' is 
not defined."
> 
> I'm sure this is because of something stupid. Would anyone care to 
publicly humiliate me with the solution?
> 
>