Edited: Setting relative path to .env (Connecting Flask code to Glitch's .env file)

How does one set .env file with the Flask code?

1 Like
  1. Add to requirements.txt this module python-dotenv · PyPI
  2. Redo your pip install -r requirements.txt if it isn’t done automatically
  3. Put the following in the module loading section of your main file
from dotenv import load_dotenv

load_dotenv()
1 Like

Yes, these have been satisfied already since day 1.

Nevertheless, I’ve re-done everything as suggested, but error still remains

1 Like

You accidentally put the string into your code not the requirements.txt

Those are separate screenshots in one image
the string is in its own
and the requirements is in its own too

Try running each line in glitch’s terminal (in the menu Tools) so type python3 with an enter
Then type each of the lines for a minimal reproducible example

from dotenv import load_dotenv
load_dotenv()
print(len(os.getenv("STATIC_DIR")))

This will print out the length of your static dir variable in .env allowing you to figure out if things are working but not print out your secret itself.

1 Like