Forums

Help with setting up environment variables

Hello friends, I am new to web development and this is my first project deploying on Pythonanywhere. I have done all steps except adding environment variables. I am just not able to figure out how this is to be done. A lot of messages in the forum talk about using a .env file but somehow I couldn't really understand what to do for it. I followed steps outlined in the link below. I added all the exports in the specified postactivate script which is located in .virtualenvs/venv/bin/postactivate. I Also added the entries in the WSGI file as outlined with only change being, I did not use 'config.settings.production' but used '<my_username>.settings'. No matter what I try, I get error when I try to run migrations saying SECRET_KEY cannot be empty. Please help me figure out what I should be doing. Not being able to deploy my project is killing me.

https://cookiecutter-django.readthedocs.io/en/latest/deployment-on-pythonanywhere.html

Have you see this?

you can do it like this just type the following export SECRET_KEY = 'your secret key'

then you get it with os.getenv("SECRET_KEY")

That will work in consoles, but the link that @conrad provided above is necessary if you want the environment variables to be available in websites that you have set up on the "Web" page inside PythonAnywhere.