2
votes

I am trying to get started with Flask, and I get 404 Not Found error for the hello world program.

The program I use:

from flask import Flask
app = Flask(__name__)

@app.route('/')
@app.route('/index.html')
def hello_world():
    return 'Hello, World'

if __name__== '__main__':
    app.run(host='localhost')

then I run

$export FLASK_APP = minimal.py
$flask run

Which returns:

* Serving Flask app "minimal"
* Forcing debug mode on
* Restarting with stat
* Debugger is active!
* Debugger PIN 127-804-808
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

When I visit http://localhost:5000 or http://127.0.0.1:5000, I get:

Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

And my host file looks like this:

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost

Any idea whats wrong? Thank you

1
Your code works for me. My only thought is that FLASK_APP is wronghayden
What did you do to run the code?hasanzuav
Solved it with using the following command: app.run(debug=True, port=4996), I think something was wrong with the default port 5000.hasanzuav
Where I found the solution: stackoverflow.com/questions/35818713/…hasanzuav

1 Answers

0
votes

Yeah, you can remove the error 404 not found in following ways: 1: You should write command netstat -a -b to check which port is not free or busy doing something or 2: write in your code app.run(port=4996) instead of app.run() which by default choose port no. 50000.