Initializing after moving to environment variables

I’m working on loading my Django settings via environment variables to make pushing changes to production easier. To do so, I’m using django-environ. If I launch my website a very specific way via my IDE it works just fine, but if I launch my site via the command line my settings are properly being loaded and saved. I’ve included more specifics below, as well as some troubleshooting steps I’ve already taken.

My best guess is that it has to do with my directory structure, but I’m not sure what the problem is.

How I Successfully Launch App Via IDE Debugging
If I open my Django base directory in my IDE (VS Code using the Python extension) and launch debugging, the site loads just fine. Stepping through the calls to I can see 2 calls to However, printing the process id with os.getpid() shows that it’s two different processes going through so that’s expected.

How I Fail to Launch App
When using the IDE debugging, opening the folder is essential - if I launch debugging with a single file open and manually specify the location of my, the site fails to load. If I attempt to launch the site via the command line arguments “python runserver” or “python runserver --noreload” it also fails.

In both of these failed attempts, the error is the same: “django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable.” When launching the app fails, I see that is called 3 times, all form the same process.

What I’ve already checked

  1. IDE Specific settings - I’ve looked at both the user and workspace settings for VS Code, but none appear to be relevant. I also commented them all out, and the result was not impacted.

  2. Directory structure - My current directory structure is listed below. I tried moving my app into the project folder in it’s own apps/${app_name} folder, but that didn’t resolve the issue.

  3. System Path - I used sys.path to print the system path at the time of executing in both situations and diff’ed them with Kdiff3, but they were exactly the same.

  4. Ensuring main directory is package - I tried adding to the main directory to ensure it was considered a package, but that didn’t impact the results either.

Current Directory Structure

  • .env

  • .env.template

  • .gitignore

  • db.sqlite3




  • env/

    • development.env
    • production.env
    • readme.txt
    • staging.env
  • App/

    • <App_files>
  • media/

    • <media_files>
  • Project/


Screenshot of Beginning Portion of

Make sure it’s not but, maybe that produces a conflict.

They actually are I just forgot mark the text as preformatted so it was converted to bolding the init text.