Flask ships with a development server, which has an interactive debugger and lazy loading.
But when you run an app using this server, you cannot access the app from other machines on the same network, for example, from your cell phone.
Can you configure the development server so the app can be accessed from other machines in the same network using the host machine’s IP?
The Flask development server uses
localhost as the default value for hostname to provide better security. According to the official documentation:
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 trust the other users on your network or have the debugger disabled, you can change this behavior.
The value of variable
host controls what address the development server listens to. By default, the value of
host is set to
localhost. You can change this value to
0.0.0.0 tells the operating system to listen on all public IPs.
There are two ways to do so:
If you are running your app on the development server using the
flask executable, you can use the
host flag and pass the new value, like so:
flask run --host=0.0.0.0
In the browser of a different machine in the same network, enter the IPv4 address of your host machine, followed by the port number, like so:
This will allow you to access your app.
If you are using
python app.py to run your app on the development server, you can add the
host='0.0.0.0' parameter to
app.run(), like so:
if __name__ == '__main__': # run app in debug mode on port 5000 app.run(debug=True, port=5000, host='0.0.0.0')
http://[your-ipv4-address]:5000 from another machine in the same network, and you should be able to access your app.
Loved by over 4 million developers and more than 90,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.
Here’s a quick look at how Sentry handles your personal information (PII).×
We collect PII about people browsing our website, users of the Sentry service, prospective customers, and people who otherwise interact with us.
What if my PII is included in data sent to Sentry by a Sentry customer (e.g., someone using Sentry to monitor their app)? In this case you have to contact the Sentry customer (e.g., the maker of the app). We do not control the data that is sent to us through the Sentry service for the purposes of application monitoring.Am I included?
We may disclose your PII to the following type of recipients:
You may have the following rights related to your PII: