1

I'm currently learning Flask and I decided to try to connect to a very simple server from other devices on my network. I followed the advice given at Flask - configure dev server to be visible across the network and changed

app.run()

to

app.run(host='0.0.0.0')

However, it does not work correctly.

I have a Flask server setup as follows:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return 'Hey there'

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

When I start the server this is the output:

Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

The server works fine when I connect via the localhost however, I always get a timeout when I try to connect from another device on the same network using:

http://<my_ip_address>:5000 

I have tried connecting to the server (which is running on my Macbook Air) from both my Windows 7 Desktop and my iPhone, with both of them receiving timeouts.

Any help regarding this matter would be greatly appreciated.

4

1 回答 1

2

同时处理请求,您可以运行 Flask:

app.run(threaded=True)

默认情况下,Flask 使用一个线程运行,因此后续请求会被阻塞,直到线程可用。在生产环境中,您需要一个像 Gunicorn 这样的 WSGI 容器来管理工作线程和线程

于 2017-04-14T10:31:48.580 回答