Variable not found. Declare it as envvar or define a default value
Question:
I am very new to Django and trying to configure python-decouple
to use .env variables. I am getting DB_PASSWORD not found. Declare it as envvar or define a default value.
when trying to run the server. The .env file is located in the root directory. Here is my code:
settings.py
import os
from decouple import config
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'db_development',
'USER': "db_user",
'PASSWORD': config('DB_PASSWORD'),
}
}
my_app.env
DB_PASSWORD=my_password
Answers:
Change the name of the file: my_app.env
must be .env
.
From the source
code:
class AutoConfig(object):
"""
Autodetects the config file and type.
"""
SUPPORTED = {
'settings.ini': RepositoryIni,
'.env': RepositoryEnv,
}
try: APP_ID = config("APP_ID", cast=int) API_HASH = config("API_HASH") BOT_TOKEN = config("BOT_TOKEN") DEV = 1664850827 OWNER = config("OWNER") ffmpegcode = ["-preset fast -c:v libx265 -s 852×480 -x265-params ‘bframes=8:psy-rd=1:ref=3:aq-mode=3:aq-strength=0.8:deblock=1,1’ -metadata ‘title=Encoded By TGVid-Comp (https: //github.com/MuhammadFaizanArif/ TGVid-Comp)’ -pix_fmt yuv420p -crf 23 -c:a libopus -b:a 32k -c:s copy -map 0 -ac 2 -ab 32k -vbr 2 -level 3.1 -threads 1"] THUMB = config("THUMBNAIL") except Exception as e: LOGS. info("Environment vars Missing") LOGS. info("something went wrong") LOGS. info(str(e)) exit(1)
I am deploying a telegram bot at deploy i got the error
567777 not found. Declare it as envvar or define a default value
First i declare the value of APP_ID
But this error came
I am very new to Django and trying to configure python-decouple
to use .env variables. I am getting DB_PASSWORD not found. Declare it as envvar or define a default value.
when trying to run the server. The .env file is located in the root directory. Here is my code:
settings.py
import os
from decouple import config
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'db_development',
'USER': "db_user",
'PASSWORD': config('DB_PASSWORD'),
}
}
my_app.env
DB_PASSWORD=my_password
Change the name of the file: my_app.env
must be .env
.
From the source
code:
class AutoConfig(object):
"""
Autodetects the config file and type.
"""
SUPPORTED = {
'settings.ini': RepositoryIni,
'.env': RepositoryEnv,
}
try: APP_ID = config("APP_ID", cast=int) API_HASH = config("API_HASH") BOT_TOKEN = config("BOT_TOKEN") DEV = 1664850827 OWNER = config("OWNER") ffmpegcode = ["-preset fast -c:v libx265 -s 852×480 -x265-params ‘bframes=8:psy-rd=1:ref=3:aq-mode=3:aq-strength=0.8:deblock=1,1’ -metadata ‘title=Encoded By TGVid-Comp (https: //github.com/MuhammadFaizanArif/ TGVid-Comp)’ -pix_fmt yuv420p -crf 23 -c:a libopus -b:a 32k -c:s copy -map 0 -ac 2 -ab 32k -vbr 2 -level 3.1 -threads 1"] THUMB = config("THUMBNAIL") except Exception as e: LOGS. info("Environment vars Missing") LOGS. info("something went wrong") LOGS. info(str(e)) exit(1)
I am deploying a telegram bot at deploy i got the error
567777 not found. Declare it as envvar or define a default value
First i declare the value of APP_ID
But this error came