I'm not sure if this is Flask specific, but when I run an app in dev mode (http://localhost:5000
), I cannot access it from other machines on the network (with http://[dev-host-ip]:5000
). With Rails in dev mode, for example, it works fine. I couldn't find any docs regarding the Flask dev server configuration. Any idea what should be configured to enable this?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
I had the same problem, I use PyCharm as an editor and when I created the project, PyCharm created a Flask Server. What I did was create a server with Python in the following way;
basically what I did was create a new server but flask if not python
I hope it helps you
While this is possible, you should not use the Flask dev server in production. The Flask dev server is not designed to be particularly secure, stable, or efficient. See the docs on deploying for correct solutions.
Add a parameter to your
app.run()
. By default it runs on localhost, change it toapp.run(host= '0.0.0.0')
to run on your machines IP address.Documented on the Flask site under "Externally Visible Server" on the Quickstart page:
If you use the flask executable to start your server, you can use
flask run --host=0.0.0.0
to change the default from 127.0.0.1 and open it up to non local connections. The config and app.run methods that the other answers describe are probably better practice but this can be handy as well.Reference: http://flask.pocoo.org/docs/0.11/quickstart/
Adding to @Shawn's answer, there is also a builtin configuration variable SERVER_NAME. we can set that to 0.0.0.0 in the config file which you specify in app.config.from_pyfile("config.py"). Also note that, this will override app.run host name.
Reference: http://flask.pocoo.org/docs/0.10/config/
Check whether the particular port is open on the server to serve the client or not?
in Ubuntu or Linux distro
Configure the application to handle remote requests
Add below lines to your project