Flask run one time with URL link but twice under replit UI

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
2 - - [30/Oct/2022 09:05:33] “POST / HTTP/1.1” 200 - (after the button click) - - [30/Oct/2022 09:05:33] “GET / HTTP/1.1” 200 - (how can I avoid that GET ?)



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'])
    res = 2 * number
  return render_template('index.html', result=res)

if __name__ == "__main__":  
  app.run(host='', port=8080)


    <meta charset="UTF-8" />
    <form action="{{ url_for('index') }}" method="POST">    
      <label  >Number:</label>  
      <input type="text" name="number" value="">  
      <input type="submit" name="next" value="Calculate">    
   Calculated number = {{result}}    
1 Like

Hi @ebgd thanks for your question.

Would it be related to @app.route having the methods GET and POST? What happens if you try to remove GET from the methods list?

Also it would be useful if you could post a link to your Repl so other users in the community can see the error for ourselves.

1 Like

https://replit.com/@ebgd/TweetArmy They did in fact post a link (unless they added that after your comment)

1 Like

Thanks @Cosmic . The link is to the web page, not the Repl. Much appreciated.