问题:
在用flask的过程中,遇到一个问题,就是想提交一个表单之后弹出一个提交成功,然后跳转到另一个页面.
但是如果用submit 则无法跳转,用button不能提交.
最后还是选择了用submit,然后在.py里面进行重定向.
前端页面x.html中:
<form action="{{ url_for('/XXX')}}" method = 'post'>
...
<input type="submit" onclick="alert('成功')" value="提交">
</form>.py中:
@app.route('/XXX',methods=['GET','POST'])
def XXX():
if request.method == 'POST':
print request.form
return redirect('index')
return render_template('x.html')
@app.route('/')
def index():
return render_template('index.html')ok,解决了
本文介绍如何使用Flask框架实现表单提交后显示提示消息并完成页面跳转的功能。通过设置前端表单元素及后端视图函数中的重定向逻辑,实现了在提交表单后弹出“提交成功”的提示,并跳转到另一个页面。

1万+

被折叠的 条评论
为什么被折叠?



