最简单的按钮不起作用
我在HTML中有一个非常简单的提交按钮,但它不起作用。最简单的按钮不起作用
main_page.html
<form class="main_page" method="POST" action=".">
<div class="form-row">
<input type="submit" name="invoer" value="Invoeren"/>
</div>
</form>
flask_app.py
from flask import Flask, render_template, request
app = Flask(__name__)
app.config["DEBUG"] = True
@app.route("/", methods=["GET", "POST"])
def main():
if request.method == "GET":
return render_template("main_page.html")
if request.form["invoer"] == "POST":
return render_template("main_page.html")
当我按一下按钮,它表明我:
------ -------------------------------------------------- -------------------------------------------------- ------------------------- -
我已经犯了这样的一个按钮之前,但当时它的工作,也许我做了一些不同的东西。我该怎么办?
错误显示ValueError: View function did not return a response
,这意味着当您单击HTML中的提交按钮时,您的POST没有返回任何对模板的响应。 Chagne代码flask_app.py
到:
from flask import Flask, render_template, request
app = Flask(__name__)
app.config["DEBUG"] = True
@app.route("/", methods=["GET", "POST"])
def main():
if request.method == "GET":
return render_template("main_page.html")
if request.method == "POST": # change code here
return render_template("main_page.html")
这将使得它的工作原理,但是,它会返回一样的模板。
这就是我需要的!谢谢:) – Jip1912
@ Jip1912如果是解决方案,请标记为接受答案,谢谢:) –
1.你看过日志的时候,和2.是否真的是你的HTML?这显然是坏的。 – jonrsharpe
1.是的,我已经这样做了,但它给了我这个https://pastebin.com/pZE0KY3E,我不知道为什么以及它意味着什么。 2. HTML只是完整html文件的一部分,我添加了复制时错过的''''。为什么downvote .... – Jip1912
把[mcve] *放在问题*中。 – jonrsharpe