0

For a basic 'hello world' webpage using flask, I'm trying to change the default host:port on the flask server from 127.0.0.1:5000 to something else using a config file. I have created a config file with just the following setting:

SERVER_NAME = '127.0.0.23:5001'

and accessed it in the python file using app.config.from_pyfile(filepath...):

I am starting the flask server using 'flask run', but when I try to access the webpage using a browser on the new host/port, it says unable to connect. I can't access the webpage on the default host/port (127.0.0.1:5000) either.

I've also tried running the flask server using app.run() (and running as a regular python script) instead of 'flask run' and the host/port change works correctly using the same config file, but how can I get it to work using 'flask run'?

My flask version is 1.0.2 and python is 3.7.1 running on Ubuntu.

Min14
  • 3
  • 1
  • 1
  • 2

1 Answers1

4

http://flask.pocoo.org/docs/1.0/config/#SERVER_NAME

Inform the application what host and port it is bound to.

This parameter only inform[s] the application what host and port it is bound to.

From this answer, you can try

flask run --host=127.0.0.23 --port=5001

Note that in production, you should definitely not use the debug server. And in development, the default config is fine for most cases.

SSteve
  • 10,550
  • 5
  • 46
  • 72
Jérôme
  • 13,328
  • 7
  • 56
  • 106