1

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

Freelancer
  • 4,459
  • 2
  • 22
  • 28

4 Answers4

8

You have to open a new tab with this url:

http://127.0.0.1:5000/
Freelancer
  • 4,459
  • 2
  • 22
  • 28
1

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.

Matthew
  • 2,232
  • 4
  • 23
  • 37
0

Try out this code:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return "<h1>Hello!</h1>"

if __name__ == "__main__":
    from waitress import serve
    serve(app, host="0.0.0.0", port=8080)

refrence Flask at first run: Do not use the development server in a production environment

Fatimh
  • 11
  • 1
-3
 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/

Sesha
  • 202
  • 1
  • 5
  • I think he did wrong copy and past because he provide the same code in comments. And btw it don't works you have an indent problem – Freelancer Jul 31 '14 at 09:43