The way I do it is to add any env variables in a .env file in the same
directory level as settings.py and then use decouple.config
<https://pypi.org/project/python-decouple/> to extract the value from the
file like this:

SECRET_KEY = config("DJANGO_SECRET_KEY")

On Sun, Feb 27, 2022 at 9:18 PM Valdinia - Office <[email protected]>
wrote:

> On W10 I defined an environment variable: SECRET_KEY
> In shell I can read the key:
>
> *>>> import os*
> *>>> os.environ.get('SECRET_KEY')*
> 'mysecretkey...'
>
> But when I'm doing the same thing in *settings.py* I get:
>
> \lib\site-packages\django\conf\__init__.py", line 90, in __getattr__
>     raise
> *ImproperlyConfigured("The SECRET_KEY setting must not be
> empty.")django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting
> must not be empty.*
>
> I found all sorts of solutions, but none works for my app. What should I
> do?
>
> Thank you!
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4afcfd9b-da0f-472e-b5d7-6339088bc4f6n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4afcfd9b-da0f-472e-b5d7-6339088bc4f6n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACbngZfD0OYUPmO%3D_U626%2BhdfQSgBKwd3KmQTjhVB1aJOxmqKg%40mail.gmail.com.

Reply via email to