DjangoでConfigプロジェクトを起ち上げ、baseアプリを作成していました。
テンプレートは、templates/base.htmlとtemplates/pages/index.htmlのみです。
veiws.py(base/views/item_views.py)は、
from django.shortcuts import render from django.views.generic import ListView from base.models import Item class IndexListView(ListView): model = Item template_name = 'pages/index.html'
です。
ファイル構成は次のようになっています。
まず、configプロジェクトのファイル構成
次に、baseアプリのファイル構成
ブラウザのエラーは次の通りです。
コンソールのエラーは次の通りです。
Internal Server Error: / Traceback (most recent call last): File "C:\Users\kgwtm\Desktop\Django\Django-Fujimoto\VegeKet\venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner response = get_response(request) File "C:\Users\kgwtm\Desktop\Django\Django-Fujimoto\VegeKet\venv\lib\site-packages\django\core\handlers\base.py", line 204, in _get_response response = response.render() File "C:\Users\kgwtm\Desktop\Django\Django-Fujimoto\VegeKet\venv\lib\site-packages\django\template\response.py", line 105, in render self.content = self.rendered_content File "C:\Users\kgwtm\Desktop\Django\Django-Fujimoto\VegeKet\venv\lib\site-packages\django\template\response.py", line 81, in rendered_content template = self.resolve_template(self.template_name) File "C:\Users\kgwtm\Desktop\Django\Django-Fujimoto\VegeKet\venv\lib\site-packages\django\template\response.py", line 63, in resolve_template return select_template(template, using=self.using) File "C:\Users\kgwtm\Desktop\Django\Django-Fujimoto\VegeKet\venv\lib\site-packages\django\template\loader.py", line 47, in select_template raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain) django.template.exceptions.TemplateDoesNotExist: pages/index.html, base/item_list.html [23/Feb/2022 16:19:38] "GET / HTTP/1.1" 500 83837
settings.pyのテンプレートは次のようにしています。
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR / 'tamplates'], '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', ], }, }, ]
なぜ、base/index.htmlだけでなく、base/item_list.htmlというテンプレートが出現しているのか?がそもそも分かりません。
templatesフォルダの設定がおかしいのでしょうか?
すみません、宜しくお願い致します。
追記
海外の方からもご回答を得たく、また多角的に情報を知る為に、Stack Overflow(英語版)に投稿しています。
解決しましたら報告させて頂きますので、どうか何卒宜しくお願い致します。
https://stackoverflow.com/questions/71233006/templatedoesnotexist-error-django-not-defined-template-appers
回答1件
あなたの回答
tips
プレビュー