Reputation: 35
Can somebody give me an example about how port number is working in the URL? I wrote a toy flask app and the default port number is 5000, without any specification in my code. How does that happen? Thank you
Upvotes: 0
Views: 473
Reputation: 119
You can think of the port number as a door through which an application on your computer is accessed by.
When you run a program on your computer that communicates with the outside world it needs to be assigned a port through which it can send and receive data, each port can only have one program associated with it as that's how your computer knows where to send the data.
So furthering the door analogy you can think of 127.0.0.1:5000 as
Go to the address 127.0.0.1
And use door 5000
As far as why your flask app is using port 5000, that's just the default port of the flask development server.
If you want to have your development server run on a different port you can run
export FLASK_RUN_PORT=****
With **** being the port you want to run on (According to this issue)
Then run
export FLASK_APP=hello.py
flask run
According to the quickstart guide
If you want to read more about ports here and here is some further reading.
Upvotes: 1