Reputation: 53
I'm using flask app factory pattern like and have this helloworld.py
file
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'This is the home page'
if __name__=="__name__":
app.run(debug=True)
Then I run the app in Terminal :
python helloworld.py
(venv) C:\Users\Jayalakshmi.S1\myproject>python helloworld.py
(venv) C:\Users\Jayalakshmi.S1\myproject>
But when I go to http://localhost:5000
it doesn't work. It says:
Can’t reach this page
Make sure the web address http://127.0.0.1:5000 is correct
What could be wrong?
Upvotes: 2
Views: 4975
Reputation: 365587
The problem is that you wrote if __name__=="__name__":
instead of if __name__=="__main__":
.
Since that will never be true, your app.run
never happens. That's why when you run the script, it just returns immediately, instead of printing out something like * Running on http://127.0.0.1:5000/
and then waiting.
You also almost always want to run Flask this way:
set FLASK_APP=helloworld.py
flask run
… instead of:
python helloworld.py
Upvotes: 4
Reputation: 10305
Your if condition is wrong. You should mention the main module which you're running...
if __name__=="__main__":
app.run(debug=True)
Upvotes: 1