我用 cookiecutter django 创建了一个新项目。我设置了环境变量 DJANGO_READ_DOT_ENV_FILE=True (将其设置为 False 也会导致 .env 文件被读取 btw。我认为 python 假设 True 的环境变量是一个字符串而不是 bool)。
在 .env 文件中有以下行:
DJANGO_SETTINGS_MODULE=config.settings.production
当我跑
python manage.py runserver
我得到以下输出:
Loading : /home/bucket/src/b2b/.env
The .env file has been loaded. See common.py for more information
Loading : /home/bucket/src/b2b/.env
The .env file has been loaded. See common.py for more information
Performing system checks...
System check identified no issues (0 silenced).
February 14, 2017 - 20:20:55
Django version 1.10.5, using settings 'config.settings.local'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
根据上述,服务器配置为 config.settings.local。我知道正在加载 .env 文件,因为DATABASE_URL
变量是正确的并且它连接到数据库。
看起来从 .env 文件加载变量的代码正在运行两次。我在 common.py 和 local.py 中放了一些打印语句来跟踪执行,结果如下。
Loading : /home/bucket/src/b2b/.env
The .env file has been loaded. See common.py for more information
End of common.py <--
End of local.py <--
Loading : /home/bucket/src/b2b/.env
The .env file has been loaded. See common.py for more information
End of common.py <--
End of local.py <--
Performing system checks...
System check identified no issues (0 silenced).
February 14, 2017 - 20:22:40
Django version 1.10.5, using settings 'config.settings.local'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
对此行为的任何帮助或解释将不胜感激。