I am reading the Flask documentation. I was told that with app.run(host='0.0.0.0')
, I could make the server publicly available.
What does it mean ? How can I visit the server in another computer (just localhost:5000
in my own computer) ?
The flask run command is the preferred way to start the development server. Never use this command to deploy publicly, use a production WSGI server such as Gunicorn, uWSGI, Waitress, or mod_wsgi. As of Flask 2.2, use the --app option to point the command at your app. It can point to an import name or file name.
The reason for this is that due to how the reload mechanism works there are some bizarre side-effects (like executing certain code twice...)
The default value is 5000 or it is the port number set in the SERVER_NAME config variable.
To answer to your second question. You can just hit the IP address of the machine that your flask app is running, e.g. 192.168.1.100
in a browser on different machine on the same network and you are there. Though, you will not be able to access it if you are on a different network. Firewalls or VLans can cause you problems with reaching your application. If that computer has a public IP, then you can hit that IP from anywhere on the planet and you will be able to reach the app. Usually this might impose some configuration, since most of the public servers are behind some sort of router or firewall.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With