I am building a project in which I take an image from the users webcam and return it to Flask as a base64 string via an AJAX call. However I want my users to be redirected after processing the image on the server side. I have tried using render_template() but it seems that render_template doesn't get executed at all. I also tried with redirect but that too didn't work. Below is the code which I am working on.
index.js
$.ajax({
type: 'POST',
url: '/upload',
data: {imagebase64: imagebase64data},
}).done(function (){
console.log(imagebase64data)
});
main.py
@app.route('/success')
def success():
return render_template('success.html')
@app.route('/fail')
def success():
return render_template('fail.html')
@app.route('/upload', methods=['GET', 'POST'])
def get_image():
img_ret = readb64()
if(prev_img(img_ret)): #this function returns a boolean and based on that I have to redirect
return redirect(url_for("success")) #this line has no effect
else:
return redirect(url_for("fail"))
Can anyone tell me what I am doing wrong? Or is there any way to redirect the user on a specific condition?