0

I'm getting a 404 error:

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

    from flask import Flask

    app = Flask(__name__)

    app.route("/")
    def index():
        return "hello world"

    app.run(host="0.0.0.0", port="80")
    * Running on all addresses (0.0.0.0)
    * Running on http://127.0.0.1:80
    * Running on http://192.168.29.41:80
    Press CTRL+C to quit
    192.168.29.41 - - [12/Mar/2023 15:32:43] "GET / HTTP/1.1" 404 -
    192.168.29.41 - - [12/Mar/2023 15:32:43] "GET /favicon.ico HTTP/1.1" 404 -
    127.0.0.1 - - [12/Mar/2023 15:37:58] "GET / HTTP/1.1" 404 -

1 Answers1

0

It's a good idea to run your Flask application on a localhost port, i.e http://127.0.0.1:5000 for example, see this StackOverflow post, and the Flask quickstart, in particular the "Externally Visible Server" section.

I'd recommend:

from flask import Flask

app = Flask(__name__)

app.route("/")
def index():
    return "hello world"

if __name__ == "__main__":
    app.run(debug=True)

if you're using python file_name.py, this starts the server on http://127.0.0.1:5000 or:

from flask import Flask
app = Flask(__name__)

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

if you're using flask run