Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the host and port that the flask command uses?

Tags:

python

flask

I want to change the host and port that my app runs on. I set host and port in app.run, but the flask run command still runs on the default 127.0.0.1:8000. How can I change the host and port that the flask command uses?

if __name__ == '__main__':     app.run(host='0.0.0.0', port=3000) 
set FLASK_APP=onlinegame set FLASK_DEBUG=true python -m flask run 
like image 472
Marco Cutecchia Avatar asked Jan 30 '17 16:01

Marco Cutecchia


People also ask

What is the default host port and port of flask?

The default value is 5000 or it is the port number set in the SERVER_NAME config variable.

How do I get my flask to run on port 80?

To get Python Flask to run on port 80, we can call app. run with the port argument. to call app. run with the port argument set to 80 to run our Flask app on port 80.


1 Answers

The flask command is separate from the flask.run method. It doesn't see the app or its configuration. To change the host and port, pass them as options to the command.

flask run -h localhost -p 3000 

Pass --help for the full list of options.

Setting the SERVER_NAME config will not affect the command either, as the command can't see the app's config.


Never expose the dev server to the outside (such as binding to 0.0.0.0). Use a production WSGI server such as uWSGI or Gunicorn.

gunicorn -w 2 -b 0.0.0.0:3000 myapp:app 
like image 200
davidism Avatar answered Sep 18 '22 06:09

davidism