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

前端 未结 2 1842
没有蜡笔的小新
没有蜡笔的小新 2021-01-12 18:21

I\'m working on my Flask project in a virtualenv. Every time I start a new terminal, I have to reinitialize these Flask environment variables:

export FLASK         


        
2条回答
  •  萌比男神i
    2021-01-12 18:47

    Modifying venv/bin/activate file is working for you because the environment variable is getting defined inside the virtual environment. When you're using python3 -m venv venv the environment variables are not present in the new virtual environment. Instead of modifying the activate file, you can instead make a shell script which:

    1. Runs venv/bin/activate
    2. Defines the environment variables
    3. Runs the server

    First, I tried writing a Python script that set them, but after research, I realized it was not possible(?).

    You could use os.environ to do the same from within, but a shell script is better.

提交回复
热议问题