Sau*_*gan 2 django postgresql webfaction
我已经在 .bash_profile 文件中设置了数据库密码的环境变量,但 PostgreSQL 的 PASSWORD 字段没有读取相同的内容。另外,我可以成功打印 production.py 文件中的密码,但 PostgreSQL 不会使用相同的密码。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '********_db',
'USER': '*****_name',
'PASSWORD':os.environ.get("RS_DB_PWD"),
}
#The below will show the password correctly.
print(os.environ.get("RS_DB_PWD"))
Run Code Online (Sandbox Code Playgroud)
我会尽量避免在中声明变量,.bash_profile而是.env在项目中创建文件(.gitignore如果使用 git,则添加它),您将在其中放置所有秘密变量并使用Python-De Couple或Dynaconf 等工具从.env.