简体   繁体   中英

flask: server can't start on port 5000

I've below code executed in a virtualenv on Linux:

# import the Flask class from the flask module
from flask import Flask, render_template

# create the application object
app = Flask(__name__)

# use decorators to link the function to a url
@app.route('/')
def home():
    return "Hello, World!"  # return a string


# start the server with the 'run()' method
if __name__ == '__main__':
    app.run(debug=True)

Execution output:

* Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

But unable to open the server on any browser using: http://localhost:5000/

Any help?

try 127.0.0.1:5000 instead of localhost:5000

if not worked again, use:

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=5000)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM