My current working directory is /home/mark/a/b
and my image resides in /home/mark/a/b/c/static
, ie the absolute path of the image is /home/mark/a/b/c/static/image.gif
.
I am using the python function send_static_file
to return an image from an endpoint via a GET
request.
My question is, why is it that I don't need to specify the full path of where the image is, in fact all I need to do is specify the image file name and it is able to retrieve the image and send it to the browser? Does send_static_file
automatically search for the static folder?
app = Flask(__name__, static_url_path='/static')
return app.send_static_file('image.gif')
If I specify anything more than just the image file name itself while I curl the endpoint I result in an error show below.
{
"message": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. You have requested this URI [/event/email/] but did you mean /event/email/ or /event ?"
}
I saw a post (first answer) somewhat answering my question Flask: How to serve static html?. But I am not quite sure what it means when they say,
static_url_path changes the URL static files are available at, not the location on the filesystem used to load the data from.
What's the difference between location on the file system and the URL static files are available at?