-1

I have written a simple Python Flask application as follows:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello_world():
    return 'Hello World2'

if __name__ == '__main__':
    app.run(debug=True, port=5000)

This code is then executed in my Virtual box Ubuntu 18.04 Server VM. It starts listening to port 5000 in my VM.

However, when I try to access it from my host browser at 127.0.0.1:6000, it is not loading.

I have enabled port forwarding in Virtualbox NAT port forwarding option as shown below:

enter image description here

How to access the Flask server from host?

user3243499
  • 2,953
  • 6
  • 33
  • 75
  • 1
    Possible duplicate of [Configure Flask dev server to be visible across the network](https://stackoverflow.com/questions/7023052/configure-flask-dev-server-to-be-visible-across-the-network) – Pierre V. Oct 10 '19 at 12:34
  • Configure the host to be `0.0.0.0` instead of `127.0.0.1`. – Maximilian Burszley Oct 10 '19 at 12:35

1 Answers1

1

Most probably your application binds to loopback network interface.

Change it to bind to all interfaces so it is accessible from the outside:

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