Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 提交按钮在';s使用flask框架连接到MySQL数据库_Python_Html_Mysql_Flask - Fatal编程技术网

Python 提交按钮在';s使用flask框架连接到MySQL数据库

Python 提交按钮在';s使用flask框架连接到MySQL数据库,python,html,mysql,flask,Python,Html,Mysql,Flask,提交按钮工作不正常。提交表单后,我将获得所需的输出。请告诉我哪里出了问题。在下面找到附加的.html和.py代码。另外,让我知道在html中使用“button”标记和“input”标记作为按钮有什么区别 main.py mysql=MySQL(app) @app.route("/",methods=["GET","POST"]) def insert(): cur=mysql.connection.cursor() i

提交按钮工作不正常。提交表单后,我将获得所需的输出。请告诉我哪里出了问题。在下面找到附加的.html和.py代码。另外,让我知道在html中使用“button”标记和“input”标记作为按钮有什么区别

main.py

mysql=MySQL(app)

@app.route("/",methods=["GET","POST"])
def insert():
    cur=mysql.connection.cursor()
    if request.form=='POST':
        print(request.form["description"])
    cur.execute("select * from test.task")
    task=cur.fetchall()
    cur.close()
    return render_template("base.html",task=task)

if __name__=="__main__":
    app.run(debug=True, port=8000)
base.html

<body>
    <h3>Table</h3>

    {% block body %}
    <div>
        <form action="/" method="POST">
            <label for="description">Description</label>
            <input type="text" name="description" id="description" placeholder="Description Input" required>
            <button type="submit">Submit</button>
        </form>
    </div>
    <br>
    <div class="=Task">
        <table>
            <tr>
                <th>S.No.</th>
                <th>Description</th>
                <th>Date and time</th>
                <th>Action</th>
            </tr>

            {% for task in task %}
            <tr>
                <td>{{loop.index}}</td>
                <td>{{task.1}}</td>
                <td>{{task.2}}</td>
                <td><a href="Update">Update</a> <a href="Delete">Delete</a>
                </td>
            </tr>
            {% endfor %}



        </table>
    </div>
    {% endblock body %}

</body>

</html>

桌子
{%block body%}
描述
提交

没有。 描述 日期和时间 行动 {任务%中的任务为%1} {{loop.index} {{task.1}} {{task.2}} {%endfor%} {%endblock body%}
尝试将其替换为:

if request.form == "POST":


你们能在后端cosole上显示错误吗?当你们点击前端的提交按钮时,它并没有显示任何错误。这是因为我已将表单的操作重定向到主页(“/”)。同时,在按下提交按钮后,它应该在根本不打印的后端控制台屏幕上打印“hello”。我并没有弄错。你们有并没有为主页和插入提供相同的路径值(@app.route(“/”,…)?现在我并没有插入任何内容。我只想让按钮正常工作并打印出所需的结果(即-->print(“hello”)。它工作了。非常感谢!!!如果您愿意,可以将其标记为接受答案。
if request.method == "POST":