【发布时间】:2020-10-04 17:08:21
【问题描述】:
我目前正在处理一个 Flask 项目,我需要在该项目中发布一个表单,并在表单发布后立即显示一个 SweetAlert。但是问题是,一旦触发了Swal方法,Post方法就会发生并返回到使用Flask设置的同一页面。我想在 SweetAlert 显示并且用户单击 Ok 按钮后刷新页面。
这是我的代码:
if (k > 0) {
e.preventDefault();
} else {
swal({
title: "Thank You",
text: "You Would Be Notified Soon",
icon: "success",
});
}
});
和我的 Python 后端:
if request.method == "POST":
email = request.form['email']
link = request.form['link']
crntprice = int(request.form['crntprice'])
btn_group = request.form.getlist("btn_group")
change_price = False
if "change_in_price" in btn_group:
change_price = True
tgt_price = 0
if "btn_change_price" in btn_group:
tgt_price = int(request.form['tgt_price'])
item = Prices(email=email, link=link, crnt_price=crntprice,
change_price=change_price, lower_price=tgt_price)
try:
db.session.add(item)
db.session.commit()
return redirect('/')
except:
return "Error"
else:
return render_template("index.html")
我只想在用户点击甜蜜警报后触发 Post-event。
【问题讨论】:
标签: javascript html flask sweetalert