Flask: `flask run` provides no way to have a port configured by default

Created on 17 Mar 2018  路  2Comments  路  Source: pallets/flask

I have a number of sites that I may be working on simultaneously, and to facilitate this I've arbitrarily designated a particular port that I run each site on in development, rather than running on the default port. I used to do this by having each project specify a hardcoded port when it called app.run:

app.run(debug=True, port=8050)

With Flask 0.12, the recommended way to run Flask is using the flask run command, which seems like a good change overall. In each application's virtualenv setup, I can set the FLASK_APP and FLASK_DEBUG environment variables so that I don't have to set them manually every time I start up the development server. However, there is no environment variable or anything of the sort to set the port, so every time I run an application, I still need to manually specify the appropriate port each time - flask run --port 8050 instead of just flask run.

In #2113 joelhed wanted to use the port in the SERVER_NAME config variable, and the issue was closed on the basis that it's technically infeasible to load app config before starting up the server, which makes sense. However, a FLASK_PORT environment variable would presumably not have this problem, and it would reduce friction significantly both for people like me and joelhed (and anyone else who for any reason can't run all their Flask applications on port 5000). Is there any chance for this to be added? I can make a pull request for this if necessary.

Most helpful comment

Click already sets options using env vars: export FLASK_RUN_PORT=8050

All 2 comments

Click already sets options using env vars: export FLASK_RUN_PORT=8050

Turns out this wasn't documented, I thought it was. See #2713.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sungjinp11 picture sungjinp11  路  3Comments

ghost picture ghost  路  3Comments

xliiv picture xliiv  路  3Comments

KeyC0de picture KeyC0de  路  4Comments

greyli picture greyli  路  3Comments