cookiecutter djangoで新しいプロジェクトを作成しました。私は環境変数DJANGO_READ_DOT_ENV_FILE = True(をFalseに設定すると.envファイルがbtwになります。私はPythonがTrueの環境変数がboolでない文字列であると仮定していると思います)。 .envファイルでdjango runserver .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ファイルがロードされていて、データベースに接続していることがわかりました。
.envファイルから変数をロードするコードも2回実行されているようです。 common.pyとlocal.pyにいくつかのprintステートメントを入れて、実行結果を以下のようにトレースします。
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.
この動作のヘルプまたは説明はありがたいです。
CookiCutterでいくつかの問題が発生したと思います-Django。 [Issue 1039](https://github.com/pydanny/cookiecutter-django/issues/1039)は 'DJANGO_READ_DOT_ENV_FILE = False'のときに環境が読み込まれる場所の問題を修正するはずです。 [このコミット](https://github.com/pydanny/cookiecutter-django/commit/3cd57880e0bfa3d48ecd338fabe7f74e71800f01)は、環境が2回読み取られたときの問題を修正する可能性があります。 – Alasdair
冗長なenv呼び出しを削除しましたが、まだ2回呼び出されています。私は問題1039を提出した人物です:-) –
runserverを実行しているときにのみ設定ファイルが2回読み込まれています。私が移行、シェルまたは他のコマンドを実行すると、それらは一度だけ実行されます。 –