I'm trying to create a flask site which gets the value of a drop down box and the string in a text box after a button click. Then redirect to another html page I made. I've been following the beginners guide to building a flask website from this site to do this (modifying it to my purposes) but I'm getting an error. HTML:
<form action="." method="POST">
<div class="col-sm-4" id="mainsubdiv">
<select class="form-control" id="op" name="choice">
<option disabled selected value></option>
<option value="1">Basic Algebra</option>
<option value="2">Quadratics</option>
<option value="3">Simultaneous equations</option>
<option value="4">Differentiation</option>
</select>
</div>
<div class="col-sm-6" id="mainsubdiv">
<input type="text" class="form-control" id="textbx" name="equation">
</div>
<div class="col-sm-2" id="mainsubdiv">
<button type="button" class="btn btn-default" href="http://google.com" id="subbtn">Submit <span class="glyphicon glyphicon-ok"></span></button>
</div>
</form>
FLASK:
from flask import Flask, redirect, render_template, request, url_for
app = Flask(__name__)
app.config["DEBUG"] = True
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "GET":
return render_template("main_page.html")
choice = request.form["choice"]
equation = request.form["equation"]
return redirect(url_for("answer_page.html") <-- syntax error here
Any help is appreciated :)
EDIT: The syntax error has now been solved meaning my main_page.html is loading but when i click my submit button the redirect ins't working. Any ideas? Is my form for POST completely wrong?