【发布时间】:2021-04-02 08:22:52
【问题描述】:
我正在构建一个项目,在该项目中,我从用户网络摄像头获取图像,并通过 AJAX 调用将其作为 base64 字符串返回给 Flask。但是,我希望在服务器端处理图像后重定向我的用户。我曾尝试使用 render_template() 但似乎 render_template 根本没有被执行。我也尝试过重定向,但这也没有用。下面是我正在处理的代码。
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"))
谁能告诉我我做错了什么?或者有什么方法可以在特定条件下重定向用户?
【问题讨论】:
标签: javascript python ajax flask redirect