简体   繁体   English

flask:服务器无法在端口 5000 上启动

[英]flask: server can't start on port 5000

I've below code executed in a virtualenv on Linux:我在 Linux 上的 virtualenv 中执行了以下代码:

# 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:执行 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/但无法在任何浏览器上使用以下命令打开服务器: http://localhost:5000/

Any help?有什么帮助吗?

try 127.0.0.1:5000 instead of localhost:5000尝试127.0.0.1:5000而不是localhost:5000

if not worked again, use:如果没有再次工作,请使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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