I am using flask and AWS to deploy my website, and I need to show a random picture from my directory (pictures are named "1.jpg" with images ranging from 1 to 56) every time the service is executed. This is my current code:
import os
import random
@application.route('/predict',methods=['POST'])
def predict():
web = str(random.choice(list(range(1,56)))) + '.jpg'
return render_template('result.html', img = web)
And my HTML code is:
<img src="static/{{img}}" width="850" height="500"/>
The program returns the HTML but shows a blank white big box instead of the image. However, if I fix the image to, let say, "31.jpg", the image works.
<img src="static/31.jpg" width="850" height="500"/>
The same problem persists in my local machine.