Inside Replit UI, when I click on the Calculate button (with number = 1), the POST method is done and I see the result (Calculated number = 2), but soon after, a GET method is executed : I loose the result and get a empty form.
This doesn’t happen outside Replit UI (with the link in a browser)
I tried to add debug=False and/or use_reloader=False in app.run, without success.
Here is the console log
1
2
172.18.0.1 - - [30/Oct/2022 09:05:33] “POST / HTTP/1.1” 200 - (after the button click)
172.18.0.1 - - [30/Oct/2022 09:05:33] “GET / HTTP/1.1” 200 - (how can I avoid that GET ?)
https://TweetArmy.ebgd.repl.co
main.py
from flask import Flask, render_template, url_for, request
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
res = 0
if request.method == 'POST':
number = int(request.form['number'])
print(number)
res = 2 * number
print(res)
return render_template('index.html', result=res)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080)
templates/index.html
<html>
<head>
<title>Test</title>
<meta charset="UTF-8" />
</head>
<body>
<h1>Test</h1>
<form action="{{ url_for('index') }}" method="POST">
<label >Number:</label>
<input type="text" name="number" value="">
<input type="submit" name="next" value="Calculate">
</form>
<h2>Results</h2>
Calculated number = {{result}}
</body>
</html>