2016-11-13 10 views
0

私は非常に単純なDjangoアプリケーションを開始していますが、htmlファイルの拡張には問題があります。Django TemplateDoesNotExist {%extends base.html%} - テンプレートはどこにありますか?

私はbase.htmlindex.htmlの両方がmy_site/my_app/templates/my_appの範囲内にあります。

、つまり my_site/my_app/templates/my_app/base.htmlmy_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を持っていますか間違った場所に保存されたファイルか何かそれ以外は?私はこれを解決することができませんでした。

+0

'BASE_DIR'はどのように定義されていますか? – yuvi

+0

これを追加するのを忘れました。 'BASE_DIR = os.path.dirname(os.path.abspath(__ file __)))')とsettings.pyは 'my_site/my_site'に保存されます – James

答えて

1

my_site/my_app/templatesまたはmy_site/templatesにある必要があります。

+0

私はmy_site/my_app /しかし、私は 'NoReverseMatch at/index /'エラーを受け取ります: '引数 '()'とキーワード引数 '{}'で 'index'を逆転させます。 0個のパターンが試されました:[] ' – James

+0

これはまったく別の問題です。あなたのテンプレートが見つからない場合は何もありません。 –

+0

ありがとうございます。私は今もすべてが機能していることを修正しました。あなたは私が求めていたものを解決した答えです - テンプレートが見つかっています。 – James

関連する問題