1
votes

I have pip-installed Flask and HTML5 on my Window-system. When I start the Hello World!-program with IDLE, I get a red message in the Python-Shell:

"* Running on xxxx://127.0.0.1:5000/". (xxxx = http)

And when I start it with app.run(debug=True) another red message appears:

"* Restarting with reloader". 

My browser (Firefox) shows no reaction. What can I do to get 'Hello World' in a new tab of Firefox?

The Code is:

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
    return "Hello World!"
if __name__ == "__main__":
    app.run(debug=True)

return and app.run are indended

3
provide the code please - Freelancer
The code is:from flask import Flask app = Flask(name) @app.route("/") def hello(): return "Hello World!" if name == "main": app.run(debug=True) - user3891230
Can you update your question with the code ? Btw which url are you using on your browser ? - Freelancer

3 Answers

8
votes

You have to open a new tab with this url:

http://127.0.0.1:5000/
1
votes

You need to actually open the page in your browser - it won't open itself. Open Firefox and navigate to

127.0.0.1:5000

(it's a URL)

When you run your code, it sits around waiting for a request from the user. When it gets a request, it'll return a response, and that's (sort of) what you see in your browser. Going to a URL is how you send that request - Flask will interpret anything sent to 127.0.0.1:5000 as a request, and try to match the URL to one of your @app.route decorators. For example, if you were to have a function decorated with @app.route("/hello"), then when you go to 127.0.0.1:5000/hello, Flask would run that function to determine the response.

-3
votes
 from flask import Flask
    app = Flask(__name__)

    @app.route("/")
    def hello():
        return "Hello World!"

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

Try this, this works for me. Open your firefox browser and go to the address given in the output. ex: http://XXXX.X.X.X:5000/