19

For some reason, 127.0.0.1:5000(port 5000) is stuck displaying my old un-updated file.

from flask import Flask
app = Flask(__name__)

@app.route("/")
def index():
    return "Home page"

@app.route("/about")
def about():
    return "About page"

if __name__ == "__main__":
    app.run()

I changed the port and it worked fine. But, why is 5000 not updating when I change and run my code? I checked to see if multiple process were running, but none were.

Honestly, this is a noob question, but I can't seem to find anyone else who's had this problem.

Nabin
  • 11,216
  • 8
  • 63
  • 98
Bryan Hinchliffe
  • 529
  • 1
  • 4
  • 14
  • 3
    ... you have another flask running somewhere... – Antti Haapala -- Слава Україні Sep 01 '17 at 21:27
  • What do you see if you run these commands: `$ telnet localhost 5000` and `$ ps aux | grep 5000` – JacobIRR Sep 01 '17 at 21:28
  • Thank you, but I actually resolved the issue. Yes, it was running somewhere. I `statnet -a -b` in command and found python was still listening on port 5000. So, I just ended the task. Now, my question is, how was it still listening if I manually decide when to run and end the server? – Bryan Hinchliffe Sep 01 '17 at 21:43
  • @BryanHinchliffe, I know this is quite old but I am having the same issue. How did you manage to solve the issue? I am working in a windows computer and Pycharm. Thanks – Ana Jun 25 '21 at 08:01
  • @Ana Sorry for the late response. I'm assuming you resolved this issue by now, but if it helps, I had to manually kill the Python process running on port 5000. You can use [this](https://stackoverflow.com/questions/39632667/how-do-i-kill-the-process-currently-using-a-port-on-localhost-in-windows) answer (option 2) to find and kill process. Hope this helps! – Bryan Hinchliffe Aug 24 '21 at 21:10
  • @BryanHinchliffe. Thanks. I resolved this by disconnected the computer, and stopped running everything. I tried all the answers in the post but none worked. – Ana Sep 07 '21 at 16:00

11 Answers11

12

Press CTR + C to end your server on the terminal and copy and paste this in the terminal to run Flask again

export FLASK_DEBUG=1 && flask run

This will set Debug mode: on

Alexey Nikonov
  • 4,958
  • 5
  • 39
  • 66
kingnanaprempeh
  • 137
  • 1
  • 4
8

To set variable in powershell -

$env:FLASK_DEBUG=1
user2959786
  • 101
  • 1
  • 2
7

No! You have not run your app in debug mode.

app.run(debug=True)

This way any changes in your code will restart the server and your code changes will reflect pretty much in real time.

Nabin
  • 11,216
  • 8
  • 63
  • 98
4

I don't know why this happens. Other answer didn't help. Community should help.

Other Two options:

  1. If you are using Visual Studio Code, Close and Open it.

  2. Uninstall and install python again.

Shaiju T
  • 6,201
  • 20
  • 104
  • 196
3

To anyone still struggling with this issue while having debug=True correctly passed to app.run(), Flask (2.0.x) documentation states that :

debug=True can be passed to enable the debugger and reloader, but the FLASK_ENV=development environment variable is still required to fully enable development mode

See https://flask.palletsprojects.com/en/2.0.x/server/

So you should also run your development server with export FLASK_ENV=development before flask run.

Beinje
  • 572
  • 3
  • 18
2

flask --app <.py file name> --debug run

1

Reload the page using Shift+ F5. But make sure app should be in debug mode i.e. app.run(debug=True).

Dhruv
  • 13
  • 7
0

If you are using the built-in app.run() try adding app.run(debug=True) It solves.

Ish
  • 113
  • 7
0

Somehow the Flask server froze. For me the solution was to kill the pythonw.exe process in the task manager.

hlorand
  • 1,070
  • 10
  • 8
0

For me, running these three commands took care of the reloading problem (windows machine):

$env:FLASK_APP = "main.py"
$env:FLASK_DEBUG = 1
flask run
Sadman Sakib
  • 557
  • 3
  • 10
0

My issue was that another application (Proton Mail Bridge) was listening on the same port (5000) my Flask app was, however no error was thrown. If you are on Windows, I would try running netstat -ab in CMD after opening as an administrator and see if any applications are listening to the same port your flask app is running on.

4.5 years later I know, but I could not find any answers on this earlier.

Drew Daniels
  • 314
  • 4
  • 16