I have written some flask api and running on http://localhost:5000/ . I want to test those api's from other computer which is connected in a same network. I am using windows 10.
What I have tried yet:
I did ipconfig/all and got ipv4 address . Wireless LAN adapter Wi-Fi:-> IPv4 Address: XX.XX.XXX.XXX(Preferred).
Ran XX.XX.XXX.XXX:5000 , but got "This site can’t be reached".
Open the port 5000 in your machine. Follow the steps:
Then try to access through <your ip>:5000
sample code is as follows:
import flask
app = flask.Flask(__name__)
app.config["DEBUG"] = True
@app.route('/', methods=['GET'])
def home():
return "<h1>Test Data</p>"
app.run(host='0.0.0.0')
and run your application through cmd as python api.py where api.py is the file name
To access a Flask app from another machine, you need the app to bind to 0.0.0.0 instead of localhost (127.0.0.1). The latter won't route to another machine.
If you're running the app via python, use run(host='0.0.0.0').
If you're running the app the flask run, add --host=0.0.0.0
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