I am very new to the flask, I am creating an application where I need to send selected value to my python code but to different routes after submit.
For Example -- I have 2 select boxes in my application now when I select an option from select box1 the selected value should go to the route "route1" and when I select an option from select box2 the selected value should go to the route "route2".
Below Is my code--
Python
app = Flask(__name__)
@app.route('/')
def index():
return render_template(
'example.html',
data=[{'name':'One Hour'}, {'name':'Three Hour'}, {'name':'Six
Hour'}, {'name':'Twelve Hour'}, {'name':'One Day'}])
@app.route("/test" , methods=['GET', 'POST'])
def test():
select = request.form.get('comp_selectbox1')
##my code
return render_template()
@app.route("/Foo" , methods=['GET', 'POST'])
def Foo():
select = request.form.get('comp_selectbox2')
##my code
return render_template()
if __name__=='__main__':
app.run(debug=False, threaded=True)
HTML
<form method="POST" action="{{ url_for('test') }}">
<form method="POST" action="{{ url_for('Foo') }}">
<div class="form-group">
<select name="comp_selectbox1" id="comp_selectbox1"
class="selectpicker form-control" style = "width:150px;background-
color:#3b8ec2;font-color:white;border:3px solid
#336600;padding:10px;font-size:10pt">
<option selected>Select test</option>
<option value="Some Link">One Hour</option>
<option value="Some Link">Three Hour</option>
<option value="Some Link">Six Hour</option>
<option value="Some Link">Twelve Hour</option>
<option value="Some Link">One Day</option>
</select>
<select name="comp_selectbox2" id="comp_selectbox2"
class="selectpicker form-control" style = "width:150px;background-
color:#3b8ec2;font-color:white;border:3px solid
#336600;padding:10px;font-size:10pt" >
<option selected>Select Foo</option>
<option value="Some Link">One Hour</option>
<option value="Some Link">Three Hour</option>
<option value="Some Link">Six Hour</option>
<option value="Some Link">Twelve Hour</option>
<option value="Some Link">One Day</option>
</select>
<br></br>
<center>
<button type="submit" class="btn btn-default" style="font-
size:15pt;color:black;
background-color:green;border:3px solid #336600;padding:10px"
>Submit</button>
</center>
</div>
</form>
Some Link -- Link which I want in function request.form.get(). The problem is Whenever I am running my application and select value from selectbox2 the value is going to the first root defined in HTML.
<form method="POST" action="{{ url_for('test') }}">
Help Appreciated!!