[Python] Environment variable coming up as 'None" using dotenv python

Discussão em 'Python' iniciado por Stack, Março 5, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use python-dotenv, but the environment variables I'm trying to pass keep coming up as 'None'. I have two files in the folder: .env & settings.py

    I have the following in my .env file: TEST_VAR=jkh45k3j4h5k34j

    And I have the following in the same folder in my settings.py:

    import os
    from dotenv import load_dotenv
    load_dotenv()

    test_var = os.getenv("TEST_VAR")

    print(test_var)


    The output I get when running python3 settings.py is: None

    Why am I not able to get the variable passed through to settings.py?

    Continue reading...

Compartilhe esta Página