I have a really easy submit button in HTML, but it doesn't work.
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")
When I click on the button, it shows me this:
------------------------------------------------------------------------------------------------------------------------------------
I already made a button like this before but then it worked, maybe I did something different. What should I do?
The error is showing that ValueError: View function did not return a response
, it means your POST didn't return any response to template when you click submit button in HTML. Chagne your code flask_app.py
to:
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")
This will make it works, however, it will return just the same template.