Configure Flask Dev Server to Be Visible Across the Network

Configure Flask dev server to be visible across the network

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.


The --host option to flask run, or the host parameter to app.run(), controls what address the development server listens to. By default it runs on localhost, change it to flask run --host=0.0.0.0 (or app.run(host="0.0.0.0")) to run on all your machine's IP addresses.

0.0.0.0 is a special value that you can't use in the browser directly, you'll need to navigate to the actual IP address of the machine on the network. You may also need to adjust your firewall to allow external access to the port.

The Flask quickstart docs explain this in the "Externally Visible Server" section:

If you run the server you will notice that the server is only
accessible from your own computer, not from any other in the network.
This is the default because in debugging mode a user of the
application can execute arbitrary Python code on your computer.

If you have the debugger disabled or trust the users on your network,
you can make the server publicly available simply by adding
--host=0.0.0.0 to the command line:

$ flask run --host=0.0.0.0

This tells your operating system to listen on all public IPs.

Connect to Flask Server from other devices on same network

I solved the issue by changing my home network profile to private instead of public, which allows my PC to be discoverable. Completely overlooked that!

Hope this helps someone!

I'm not able to access my python server outside of local network, but static ip is working fine when I create virtual server

It is because flask runs on localhost (127.0.0.1) by default, so for accessing flask server globally you have to pass anywhere access IP i.e. 0.0.0.0 .

app.run(host = '0.0.0.0', port = 5000)

Configure my local flask server to be available to other devices under same wifi network

The Flask dev server should not be used in production as it is not designed to be efficient and secure. Flask Deployment

To make the flask dev server visible on LAN/WLAN add the host parameter to run on machine's IP Address

app.run(host='0.0.0.0', port=5000)

To Access the web server use private ip address(LAN/WLAN) of the machine running the flask server 192.168.1.23:5000

How to access Flask test server from the outside of local network?

What you'll need to do is make your specified port available on your router. This is done with port forwarding. The location of this tab can switch depending on your router provider but once this is done you can just visit This link which shows your public IP. Then you can just visit: 000.00.000.00:5000 <-- Replace zero's with public IP.

How can one configure flask to be accessible via public IP interface?

run flask using

app.run(host="0.0.0.0:PORT#")

look for your IPv4 Address using ifconfig in your command prompt, and in your browser you can access your app using your ipaddress:port#

You might have to configure your router (port forwarding) to make it publicly available, otherwise you can
download/use https://ngrok.com/ ----> This will expose your localhost behind a NaT or Firewall to the internet.

Once you download, you can configure it by running

ngrok http localhost:5000

this will provide you a RANDOMsubdomain.ngrok.io and you can test your app from pretty much anywhere

Are a WSGI server and HTTP server required to serve a Flask app?

When you "run Flask" you are actually running Werkzeug's development WSGI server, and passing your Flask app as the WSGI callable.

The development server is not intended for use in production. It is not designed to be particularly efficient, stable, or secure. It does not support all the possible features of a HTTP server.

Replace the Werkzeug dev server with a production-ready WSGI server such as Gunicorn or uWSGI when moving to production, no matter where the app will be available.


The answer is similar for "should I use a web server". WSGI servers happen to have HTTP servers but they will not be as good as a dedicated production HTTP server (Nginx, Apache, etc.).


Flask documents how to deploy in various ways. Many hosting providers also have documentation about deploying Python or Flask.



Related Topics



Leave a reply



Submit