質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Q&A

解決済

1回答

1632閲覧

TemplateDoesNotExist Error Django 作成していないテンプレートが挙げられる

PolymetisOutis7

総合スコア16

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

0グッド

0クリップ

投稿2022/02/23 08:17

編集2022/02/25 02:05

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ozwk

2022/02/24 02:09

マルチポスト https://stackoverflow.com/questions/71233006/templatedoesnotexist-error-django-not-defined-template-appers https://teratail.com/help > teratailでは、マルチポスト※の推奨はしていません。 やむを得ず複数のサイトに質問を投稿された場合は、質問内容にマルチポストをする理由を書き、他のサイトの投稿へのリンクを貼ってください。 また、解決した際には必ずteratail及びすべての投稿に解決した旨と、どのように解決したかを記載してください。
PolymetisOutis7

2022/02/25 02:06

ご指摘、コメントありがとうございます。 対応致しました。 宜しくお願い致します。
guest

回答1

0

自己解決

お恥ずかしいミスでした。

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', ], }, }, ]

'DIRS': [BASE_DIR / 'tamplates'],
が原因でした。
'DIRS': [BASE_DIR / 'templates'],
が正しい記述です。

初めて見たエラーで、特にエラーメッセージに出てくるbase/item_list.htmlなど設定もしておらず、見たこともなく、settings.pyも何度か見直したはずなんですが、初歩的な間違いをしていました。

すみません、ありがとうございました。

投稿2022/02/26 01:42

PolymetisOutis7

総合スコア16

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問