0

This project was working good until I reinstalled django-environ to make DB_USER, exc After I tried to execute and I had this error ...

settings.py

from pathlib import Path
import os 
import environ

env = environ.Env(
    #Set casting, default value
    DEBUG=(bool, False)
)

READ_DOT_ENV_FILE = env.bool('READ_DOT_ENV_FILE', default=False)

"""if READ_DOT_ENV_FILE:
    environ.Env.read_env()"""

#reading .env file
#environ.Env.read_env()

#False if not in os.environ
DEBUG = env('DEBUG')
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env('SECRET_KEY')

DATABASES FROM settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': env("DB_NAME"),
        'USER': env("DB_USER"),
        'PASSWORD': env("DB_PASSWORD"),
        'HOST': env("DB_HOST"),
        'PORT': env("DB_PORT"),
    }
}

.env file it is located at the same directory like settings.py

DEBUG=False
SECRET_KEY='KEY'
DB_NAME=DB
DB_USER=USER
DB_PASSWORD=PASSWORD
DB_HOST=HOST
DB_PORT=

And error

File "D:\CRM\web\settings.py", line 96, in <module>
    'USER': env("DB_USER"),
  File "D:\CRM\env\lib\site-packages\environ\environ.py", line 197, in __call__
    return self.get_value(
  File "D:\CRM\env\lib\site-packages\environ\environ.py", line 407, in get_value
    raise ImproperlyConfigured(error_msg) from exc
django.core.exceptions.ImproperlyConfigured: Set the DB_USER environment variable
(env)
#I deleted the comment. SOLVED!
environ.Env.read_env()

1 Answers1

1

add this line

env = environ.Env(
    #Set casting, default value
    DEBUG=(bool, False) )

add this

environ.Env.read_env()
Mohamed Beltagy
  • 593
  • 4
  • 8