【问题标题】:Form button that calls a python function调用python函数的表单按钮
【发布时间】:2018-05-08 21:49:59
【问题描述】:

调用python函数的表单按钮

大家好! 我把我的问题暴露给你,如果你能帮助我,我将不胜感激! 我有一个在 python 形状内只有一个按钮的页面:

<form action = "http://localhost:5000/updateDB" method = "POST">
  <p><input type = "submit" value = "submit" /></p>
</form>
...
{% with success = get_flashed_messages(category_filter=["success"]) %}
  {% if success %}
    <ul class=flashes>
    {% for s in success %}
      <li>{{ s }}</li>
    {% endfor %}
    </ul>
  {% endif %}
{% endwith %}

python函数如下:

@app.route('/updateDB',methods = ['POST', 'GET'])
def updateDB():
   if request.method == 'POST':
      log = updateDB()
      if log == 0
          flash(u'Success','success')
      return render_template("result.html")

但它不起作用,它不调用函数,因此它不打印消息。我究竟做错了什么? 我只能使用python、flask、html、css和javascript(这是一个学校项目)

【问题讨论】:

    标签: html python-3.x flask


    【解决方案1】:

    如果你在 if 语句中缺少一个 : ,它应该是

    if log == 0:
        flash(u'Success','success')
        return render_template("result.html")
    

    其次,调用你的函数 updateDB() 本身会导致

    RuntimeError: 超出最大递归深度

    【讨论】:

    • 对不起,为了正确起见,我做一个澄清:我放了一个大概的代码,因为我不确定你可以用这种方式制作表格,所以我想要一个建议:)实际上,在我的代码中有“:”,并且该函数以另一种方式调用。
    猜你喜欢
    • 2019-07-21
    • 2021-12-31
    • 2022-11-14
    • 2017-03-27
    • 2023-03-31
    • 2015-09-03
    • 2017-04-21
    • 2014-11-01
    • 2018-03-03
    相关资源
    最近更新 更多