2016-03-19 6 views
3

私は新しいDjangoユーザーです。私の新しい1.9.4プロジェクトでは、私は "personal"という新しいアプリを作成しました。これは、アプリケーションのソースツリーです:Django 1.9.4テンプレートの継承が機能しません

個人/ view.pyで
personal 
-templates 
--personal 
---main.html 
---content.html 

content.html

{% extends 'personal/main.html' %} 

{% block content %} 
<p>My personal content</p> 
{% endblock %} 

from django.shortcuts import render 
def index(request): 
    return render(request, 'personal/main.html') 
main.htmlとで

<!doctype html> 
    <html lang="en"> 
    <body> 
    <p>Hi everyone!</p> 
    {% block content %} 
    {% endblock %} 
    </body> 
    </html> 

最後にsettings.pyのテンプレート設定:

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [], 
     '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はコンテンツブロック「個人用コンテンツ」を拡張せずに「こんにちは」のみをレンダリングします。

なぜですか? ありがとう

答えて

4

実際のテンプレートの代わりにレイアウトをレンダリングしました。あなたのビューは:

from django.shortcuts import render 
def index(request): 
    return render(request, 'personal/content.html') 
+0

です。ありがとう! – Arcy

関連する問題