Is adding Flask env vars to the virtualenv's activate script OK?

Yes, setting environment variables in the virtualenv's activate script is fine for managing your development environment. It's described in Flask's docs. They're only active when the env is activated in the terminal, and you have to remember to add them if you create a new env, but there's nothing wrong with it.


With Flask 1.0, you can use dotenv files instead. Install python-dotenv:

pip install python-dotenv

Add a .flaskenv file:

FLASK_APP=server

And the flask command will automatically set them when running a command:

flask run

The advantage of this over messing with the venv is that you can commit this file so it applies anywhere you work on the code.