Reputation: 15579
I am using PyCharm on Windows and want to set the environment variables for Django website. I have tried two approaches:
I am setting the values in the project's venv:
activate.bat
@echo off
set "VIRTUAL_ENV=D:\Git\QV-PublicWebsite\venv"
set DJANGO_SECRET_KEY='random'
...
activate.ps1
...
$VIRTUAL_ENV = $BASE_DIR
$env:VIRTUAL_ENV = $VIRTUAL_ENV
$env:DJANGO_SECRET_KEY='random'
...
When I load the project in PyCharm, I can see that the venv is active.
But when I start debugging the project, I am not able to read the values:
This is the settings that I have for debugging the project:
I have also tried using EnvFile tab and import my .env
file
This way, when I debug the project in PyCharm, the environment variables are set as expected.
However when I want to build the migrations then the environment variables are not set again!
Upvotes: 0
Views: 1483
Reputation: 61
If you want to add a virtual environment for your Django Website the simple way is as follows:-
->. Create Environment variable by : python -m venv <virtual_env_name>
->. After the Virtual environment got created you have 2 approaches to activating it
i.By using CMD. cd <virtual_env_path>\Scripts\activate.bat [NOTE : Please make sure to use Backward slash '\']
ii. By using Pycharm interpreter - go to settings in Pycharm than select interpreter settings and add python interpreter - in add settings select interpreter and in scripts dir choose python.exe and you are ready to use your virtual environment
Upvotes: 1