I'm designing a small web calculator using Bootstrap and Flask. However I'm close finished, here is my code:
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
return render_template('finish.html',
number1=request.form['number1'],
number2=request.form['number2'],
finish=(request.form['number1'] * request.form['number2']))
else:
return render_template('index.html')
And here is a part of index.html
:
<form>
<div class="form-group">
<input type="text" class="form-control" name="number1" placeholder="Number1">
</div>
<div class="form-group">
<input type="text" class="form-control" name="number2" placeholder="Number2">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
So I wish receive a POST, and return the result. But when I trying to run my program, enter these two number and submit them. The program didn't receive a POST, here is the log:
127.0.0.1 - - [24/Sep/2015 22:20:25] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [24/Sep/2015 22:20:25] "GET /dist/js/bootstrap.min.js HTTP/1.1" 404 -
127.0.0.1 - - [24/Sep/2015 22:20:25] "GET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1" 404 -
127.0.0.1 - - [24/Sep/2015 22:20:29] "GET /?number1=12&number2=32 HTTP/1.1" 200 -
So the program received something like GET /?number1=12&number2=32
, not a post. And the web page is still at /
. How do I change this to POST or use /?number1=12&number2=32
?