Forums

Flask not serving images from static folder

I had a webapp running on flask on my machine and it worked, the images were displayed on the webpage, but after uploading it to pythonanywhere, it images get 404 errors.

image tag:

img src="{{ url_for('static', filename ='path/to/{{image}}.jpg') }}"

directory structure:

app/
    server.py
    templates/
    static/
        path/to/image.jpg

my code replaces {{image}} with the actual file name, and i viewed the page source and the path looks correct there, it get: /static/path/to/image.jpg, but it still does not show the image. Why would it work on my machine, but not on pythonanywhere?

thanks in advance for the help.

You need to serve the static files using a static file mapping because flask only does that when you're using the debug server. We have a help page for the here: http://help.pythonanywhere.com/pages/StaticFiles/

resolved, thanks

same problem

Have you looked at the help page that I linked to?

@tanjaro -- check your error logs and static file mappings set for the web app and make sure that you provided correct paths