By default, a Flask application runs on 127.0.0.1:5000, which makes it accessible only on the same machine. To access the application from other devices on the same network, the host IP address can be changed.
Using host Parameter
host parameter in app.run() is used to specify the IP address on which the application should run. Setting the host to a local network IP allows other devices on the same network to access the application.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, World! this application runing on 192.168.0.105'
if __name__ == '__main__':
app.run(host='192.168.0.105')
Output


Now, the app will be accessible from other devices on the same network using 192.168.0.105:5000.
Using Command Line
Instead of modifying the script, we can set the host and port directly when running the app from the terminal. Here are the steps:
1. Set the Flask app environment variable:
set FLASK_APP=app.py
2. Run the Flask app with a custom IP and port:
flask run --host=192.168.0.105 --port=5000
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, World!'
if __name__ == '__main__':
app.run()
Output


We can make it accessible on a different IP by using the command "flask run --host=192.168.0.105 --port=5000".