settings.pyのTEMPLATESにある 'DIRS'はなぜ 'APP_DIRS'がFalseに設定されている場合にのみ効果がありますか?なぜ 'DIRS'はAPP_DIRSがFalseのときだけ効果がありますか?
カスタムHTMLウィジェットを読み込もうとしましたが、 'DIRS'を変更しても 'TemplateDoesNotExist'がスローされたときに 'Template-loader postmortem'は変更されませんでした。 「APP_DIRS」をFalseに設定すると、「DIRS」設定が突然効果を上げました。
私は同様の質問を検索しようとしましたが、回答が見つかりませんでした。私はまた、ドキュメントを見てきましたが、DIRSやAPP_DIRSについての段落でも、他のものがそうでない場合には、どちらかが動作するとは言いません。
例1:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'), '/Users/jonas/Documents/jobb/dynamicSurvey/survey/templates/django/forms/widgets'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
この出力を与える:
をエンジンジャンゴを使用:
テンプレートローダは
Djangoはこの順序で、これらのテンプレートをロードする試みを死後
django.template.loaders.filesystem.Loader: /Users/jonas/venv/lib/python3.6/site-packages/django/forms/templates/horizontal_select.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/jonas/venv/lib/python3.6/site-packages/nested_admin/templates/horizontal_select.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/jonas/venv/lib/python3.6/site-packages/django/contrib/admin/templates/horizontal_select.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/jonas/venv/lib/python3.6/site-packages/django/contrib/auth/templates/horizontal_select.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/jonas/Documents/jobb/dynamicSurvey/survey/templates/horizontal_select.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/jonas/venv/lib/python3.6/site-packages/tellme/templates/horizontal_select.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/jonas/venv/lib/python3.6/site-packages/tinymce/templates/horizontal_select.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/jonas/venv/lib/python3.6/site-packages/django/forms/templates/horizontal_select.html (Source does not exist)
例2:
この出力を与える:
をエンジンジャンゴを使用:
テンプレートローダは
Djangoはこの順序で、これらのテンプレートをロードする試みを死後
django.template.loaders.filesystem.Loader: /Users/jonas/Documents/jobb/dynamicSurvey/templates/survey/survey_detail.html (Source does not exist)
django.template.loaders.filesystem.Loader: /Users/jonas/Documents/jobb/dynamicSurvey/survey/templates/django/forms/widgets/survey/survey_detail.html (Source does not exist)
私が「engine django」を正しく理解していれば、例2の最後の行( 'django.template.loaders.filesystem.Loader:/ Users/jonas/Documents/jobb/dynamicSurvey/survey/templates/django/forms/widgets/survey/')は、DIRSの設定が有効であれば、例1で検索する必要があります。
私はスタックに新しく、私の質問を批判することは自由です。
これはどのDjangoバージョンですか? –
Django 1.11.2 – Jonas