私は非常に単純なDjangoアプリケーションを開始していますが、htmlファイルの拡張には問題があります。Django TemplateDoesNotExist {%extends base.html%} - テンプレートはどこにありますか?
私はbase.html
とindex.html
の両方がmy_site/my_app/templates/my_app
の範囲内にあります。
、つまり my_site/my_app/templates/my_app/base.html
とmy_site/my_app/templates/my_app/index.html
です。
index.html
ファイル内には、私は{% extends 'base.html' %}
があります。
マイsettings.py
ファイルが
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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',
],
},
},
]
を持っている。しかし、私はhttp://127.0.0.1:8000/index/
で私のインデックスビュー訪れるとき:
def index(request):
return render(request, 'my_app/index.html')
を私は次のエラーを取得する:
TemplateDoesNotExist at /index/
base.html
Request Method: GET
Request URL: http://127.0.0.1:8000/index/
Django Version: 1.10.3
Exception Type: TemplateDoesNotExist
Exception Value: base.html
は私がbase.html
を持っていますか間違った場所に保存されたファイルか何かそれ以外は?私はこれを解決することができませんでした。
'BASE_DIR'はどのように定義されていますか? – yuvi
これを追加するのを忘れました。 'BASE_DIR = os.path.dirname(os.path.abspath(__ file __)))')とsettings.pyは 'my_site/my_site'に保存されます – James