0

I'm writing a basic "Hello world" program in Flask which exits without giving any output. The following is my code:

import flask

app = flask.Flask(__name__)


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


if __name__ == "main":
    app.run(debug=True, host='0.0.0.0')
    print("test")

I'm getting the following output:

Process finished with exit code 0

But my http server is not starting, I get the following output:

$ curl -I http://127.0.0.1:5000
curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused
Manu Jain
  • 89
  • 5

1 Answers1

5

When a python file is executed, the value of __name__ is "__main__" and not "main". Your code isn't entering into the if statement, which is why the Flask server never starts.

import flask

app = flask.Flask(__name__)


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


if __name__ == "__main__":  # There is an error on this line
    app.run(debug=True, host='0.0.0.0')
    print("test")
Diptangsu Goswami
  • 5,554
  • 3
  • 25
  • 36