I have created a flask app that accesses images in a folder specified in a config file. For some reason, when I specify the full path to the folder (img_folder: '/user/userName/static/img/') I get a 404 error but when I specify the relative path (img_folder: './static/img/') it works. Looking at my terminal, the 404 error specifies the correct path and file, so the path is certainly correct. What is going on? How can I use the full path without receiving a 404.
This is what it looks like when I specify the full path in the config folder:
img_folder : '/user/userName/static/img/'
This is the HTTP error when I specify the full path in the config:
127.0.0.1 - - [06/Jul/2018 11:26:25] "GET /user/userName/static/img/lion.jpg HTTP/1.1" 404
When I specify the relative path in the config folder like this:
img_folder : './static/img/'
I don't get the 404 error
In my flask app file, I have a route that uses the files from the folder as such:
files = os.listdir(img_folder)
@app.route('/', methods=['GET', 'POST'])
def init():
return render_template('display.html', file=files[0])
display.html
<!doctype html>
<div id='img_area'>
<img src="{{file}}"></img>
</div>
</html>
So the file is not being displayed when the full path is used, but is being displayed with the relative path.