-2

When I run the code:

from flask import Flask
app = Flask(__name__)


@app.route('/')
def index():
    return "Hello, world!"

if __name__ == '__main__':
    app.run(debug=True)

I get the string "Hello, world!" in the chrome browser, but when I change the code:

return "Hello, world!"

to:

return "Hello"

The browser also shows the "Hello, world!" not the "Hello".

How does that happen?

jcxu
  • 86
  • 5
  • Did you restart your server ? – Raja Simon May 31 '16 at 08:46
  • @RajaSimon flask should reload itself with `debug=True` – Jieter May 31 '16 at 08:56
  • @Jieter Yes it will reload.. if he changes the return string it will reload. I'm thinking why is not reloading... – Raja Simon May 31 '16 at 08:57
  • 1
    Just copied your example and ran it locally, I see flask reload on file change ` * Detected change in '[...]flask-test/app.py', reloading`, and get `Hello` after changing the return value as expected. – Jieter May 31 '16 at 08:59
  • Maybe there're something wrong with my Flask configuration ,but I just follows the Flask tutorial document. – jcxu May 31 '16 at 09:09
  • @jcxu if not worked .. try app.run(debug=True, use_reloader=False) – Raja Simon May 31 '16 at 09:37
  • try a different browser, if you see the new results on the browser its probably a cache issue. Depending on your browser you should blow away the cache to see the change. If that gives you the results you want look into http://stackoverflow.com/questions/28627324/disable-cache-on-a-specific-page-using-flask – Busturdust May 31 '16 at 14:07
  • Yeah, I have tried the chrome and microsoft-edge,the result has no change, I noticed that the console didn't show the HTTP response like`127.0.0.1 - - [31/May/2016 11:03:15] "GET /?foo=1 HTTP/1.1" 200`, I don't know why. – jcxu May 31 '16 at 15:10

1 Answers1

1

Maybe the page is cached by your browser? Use Ctrl + F5 to force reload , or append ?foo=1 to the url to make your browser make a new request to your web app.

Jieter
  • 4,101
  • 1
  • 19
  • 31
  • Thanks for your advice, I have tried the `Ctrl + F5` or append the `?foo=1` to the url, but the browser also shows the **Hello, world!** – jcxu May 31 '16 at 08:44
  • Hmm, you are using `debug=True`, so I would expect flask to reload the changed file after you edit it. Are you sure you saved it? Do you see flask reloading after you save the file? – Jieter May 31 '16 at 08:54
  • Yes, I see `Restarting with stat, Debugger is active!, Debugger pin code: 334-192-961` – jcxu May 31 '16 at 08:58
  • Do you see every request you make in the console like this: `127.0.0.1 - - [31/May/2016 11:03:15] "GET /?foo=1 HTTP/1.1" 200 -` – Jieter May 31 '16 at 09:05
  • Yes, if I set `app.run()` not the `app.run(debug=True)`the console will show `Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)`,but if I use `debug=True`, the console shows `Restarting with stat, Debugger is active!, Debugger pin code: 334-192-961` – jcxu May 31 '16 at 09:16
  • Hmm, hard to see what's going wrong, I tried your exact example and it just worked™... – Jieter May 31 '16 at 09:17
  • I just noticed that my console didn't show the HTTP response like you said `127.0.0.1 - - [31/May/2016 11:03:15] "GET /?foo=1 HTTP/1.1" 200`, do you have any idea about that? – jcxu May 31 '16 at 15:14
  • @jcxu: maybe you are running multiple instances on different ports? – Jieter May 31 '16 at 15:21