0

I have establish the flask project,And it can run successfully,but I want to put my images directory in my web root path,make the images can be showed by visiting url http://mywebsite.com/images/test.jpg

I have tried to put the images dir under the static dir and under the website dir and under the app dir,they are both no working.

I search google ,and put the images dir under static dir try

@app.route('/images<path:path>')
def return_images(path):
    return send_from_directory(os.path.join(app.root_path,'static/images'),path)

then visite http://mywebsite.com/images/test.jpg it's no working..

I am a newer for python flask,so How to server static file in python flask?

Cœur
  • 37,241
  • 25
  • 195
  • 267
elsonwx
  • 1,431
  • 3
  • 16
  • 26
  • check this http://stackoverflow.com/questions/32014332/unable-to-load-images-on-web-pages-in-flask-web-application – sameera sy Jan 24 '16 at 04:45
  • the images path have been writen in front page,so I want to make images can be viewed by visite the url like [link](ttp://abc.com/images/test.png) – elsonwx Jan 24 '16 at 04:51
  • 1
    for performance reasons it's better if you let your web server directly deliver the images, so python doesn't have to deal with them too – replay Jan 24 '16 at 11:24
  • @mauro.stettler yes,finally I server the images dir with nginx.just configure the location endpoint in nginx configuration file.thank you. – elsonwx Jan 24 '16 at 11:38

0 Answers0