我有一个页面/contact.html。它有一个按钮,提交后会将我带到用户登录的第二页(algo.html)。在第二页上,我有两个按钮,但我无法响应。这是我的代码:
@app.route('/contact', methods = ['GET', 'POST'])
def contact():
form = ContactForm()
if request.method == 'POST':
return render_template('algo.html')
if request.method == 'POST' and request.form['submit'] == 'swipeleft':
print "yes"
在 contact.html 上我有:
<form action="{{ url_for('contact') }}" method=post>
{{ form.hidden_tag() }}
{{ form.name.label }}
{{ form.name }}
{{ form.submit }}
在 algo.html 上我有:
<input type = "submit" name = "submit" value = "swipeleft" method=post>
<input type = "submit" name = "submit" value = "swiperight" method=post>
最佳答案
在您的 algo.html
模板中,您需要将表单提交回同一网址 /contact
,因为这是您检查 值的地方向左滑动
:
<form action="{{ url_for('contact') }}" method="post">
<input type = "submit" name = "submit" value = "swipeleft" />
<input type = "submit" name = "submit" value = "swiperight" />
</form>
关于python - Flask Python 按钮没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19796253/