In my Flask app hosted on Heroku, I use this code to start the server:
if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
app.run(host="0.0.0.0", port=port)
When developing locally, this will use port 5000, in production Heroku will set the PORT
environment variable.
(Side note: By default, Flask is only accessible from your own computer, not from any other in the network (see the Quickstart). Setting host="0.0.0.0"
will make Flask available from the network)