python - Flask Python 按钮没有响应

标签 python html flask

我有一个页面/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/

相关文章:

php - 如何通过 SQL 在 PHP 中创建动态表

python - Flask-SQLAlchemy 小写索引 - 跳过功能,SQLAlchemy 反射不支持

python 用 pandas 绘图

python - 类和对象上的 `__new__` 和 `__init__`

javascript - javascript如何识别对象

html - 完全新手!非常不知道如何通过 Flask 发送 json 数据以显示在 HTML 网页上?

python - 如何在 Flask 中重定向到绑定(bind)多路由的 URL

python - 键入 : incompatible type when declare typing. 类型 []

python - Python 中 Y 参数到 z 参数

html - 如何将 3 个 block (span、span、input)放置在垂直对齐的一行中?