Forums

Issue with enviroment variables in Bash

Hi, I'm trying so set up a file location as an enviroment variable so I can test my code in both local and Pythonanywhere.

I have tried to follow these steps: https://help.pythonanywhere.com/pages/environment-variables-for-web-apps/.

In /home/vtpower/inventario/ I have created an .env file with the following content:

STOCK_DIR = '/home/vtpower/stock'
SECRET_KEY = 'DjangoSecretKey'

I have installed python-dotenv in my virtualenv and added the following to the WSGI file:

from dotenv import load_dotenv

project_folder = os.path.expanduser('~/inventario')
load_dotenv(os.path.join(project_folder, '.env'))

But when I reload the virtualenv it tells me the following:

(stockvt) 10:15 ~/inventario (master)$ workon stockvt
bash: STOCK_DIR: command not found
bash: SECRET_KEY: command not found

What I am missing?

Thanks for your help

are you sure your .env file can look like that? I thought you can't have spaces between the '=' signs

Hello Conrad, that was exactly the issue!

Thanks a lot for your help!