I am creating a gif dynamically in the project.
When the url is called, the gif is created and the page is loading fine, but the problem is that for some reason the loading of an animated gif inside the page is giving me 404 NotFound.
I'm getting the parameter from the URL in the get method. I tried this. Do you have any advice?
def create_image_with_ball(width, height, ball_x, ball_y, ball_size):
img = Image.new('RGB', (width, height), (255, 255, 255))
draw = ImageDraw.Draw(img)
# draw.ellipse takes a 4-tuple (x0, y0, x1, y1) where (x0, y0) is the top-left bound of the box
# and (x1, y1) is the lower-right bound of the box.
draw.ellipse((ball_x, ball_y, ball_x + ball_size, ball_y + ball_size), fill='red')
return img
app = Flask(__name__, template_folder='templates') #../{{ user_image }}
app.config['UPLOAD_FOLDER'] = GIF_FOLDER
@app.route('/')
@app.route('/getpixel')
def get_meth():
invoice_num = request.args.get('invoice_num')
frames = []
x, y = 0, 0
for i in range(5):
new_frame = create_image_with_ball(10, 10, x, y, 40)
frames.append(new_frame)
x += 40
y += 40
frames[0].save('.\gif_created\inv_im_open_'+invoice_num+'.gif', format='GIF', append_images=frames[1:], save_all=True, duration=100, loop=0 )
#full_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'inv_im_open_'+invoice_num+'.gif')
full_filename = os.path.join(app.config['UPLOAD_FOLDER'],'inv_im_open_' + invoice_num + '.gif')
print(app.config['UPLOAD_FOLDER'])
print(os.path.curdir)
return 'NO data' if invoice_num is None else render_template("index.html", user_image = full_filename)
app.run(host='0.0.0.0', port=5000)
The web page look like this:
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<img src="{{user_image}}" alt="{{ user_image }}">
</body>
</html>
As I said before, the page is loading fine the problem is when the app is loading the gif created in the directory.
127.0.0.1 - - [13/Sep/2019 09:38:01] "GET /getpixel?invoice_num=2136 HTTP/1.1" 200 -
127.0.0.1 - - [13/Sep/2019 09:38:01] "GET /gif_created/inv_im_open_2136.gif HTTP/1.1" 404 -