1

I have python application one of the method returning list of file names in JSON format. I tried to bind the file names to local folder path when I render the template images are not loading in browser.

I tried several ways to bind the path

img src="./localpath/filename.png"



img src="localpath/filename.png"



imagename = os.path.join(os.getcwd(), 'foldername/'+ filename.png)

Even i tried to load image with local host static path but still unable to load images. enter image description here Can some one help me out on this?

Thanks In advance

2 Answers 2

2

By default Flask serves static content from the static folder of your project. You can then create URLs for these files using url_for('static', filename='image.png') (assuming the location static/image.png, see also).

Please note that url_for should be your go-to way of building URLs as it takes a lot of tasks off your plate.

Sign up to request clarification or add additional context in comments.

Comments

1

Flask serves images through the static folder. So add filename.png in a folder called static and reference it from there.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.