简体   繁体   中英

Setting environment variables in virtualenv (Python, Windows)

As the title suggests, I'm trying to use a environment variable in a config file for a Flask project (in windows 10).

I'm using a virtual env and this far i have tried to add set "DATABASE_URL=sqlite:///models.db" to /Scripts/activate.bat in the virtualenv folder. But it does not seem to work. Any suggestions?

Flask does not automatically take configuration variables from environment variables. You have to set them manually like so:

app.config.from_envvar('YOURAPPLICATION_SETTINGS')

More info regarding configuration can be found here .

To set an environment variable in Windows, you should do as described here :

setx DATABASE_URL=sqlite://something.something

The problem was that PyCharm does not activate the virtualenvironment when pressing the run button. It only uses the virtualenv python.exe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM