I am new to python and trying to create a simple API. below is the code for the same.
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == '__main__':
app.run(host='0.0.0.0',port=5000)
I have saved this as code as "hello-world.py". When I am trying to run this file in command prompt using python command
python hello-world.py
Command executed in command prompt
Here I have no error but web page is not getting displayed. Below is the error on web page.
http://localhost:5000/
This site can’t be reached localhost refused to connect. Search Google for localhost 5000 ERR_CONNECTION_REFUSED
1st Issue - Even after running the code properly, why the web page is not displayed
Now, I enter python command in my command prompt and then I try running file again python hello-world.py
. Here I am getting the below error
>>> File "<stdin>", line 1
python hello-world.py
^
SyntaxError: invalid syntax
2nd Issue - Why I am getting an error while trying run the hello-world.py
Please guide me on how to resolve this issue.