Python Django 1.9.4模板继承不起作用
我是Django的新用户。在我新的1.9.4项目中,我创建了一个名为“personal”的新应用程序。这是应用程序源目录树:Python Django 1.9.4模板继承不起作用,python,django,Python,Django,我是Django的新用户。在我新的1.9.4项目中,我创建了一个名为“personal”的新应用程序。这是应用程序源目录树: personal -templates --personal ---main.html ---content.html 在personal/view.py中: from django.shortcuts import render def index(request): return render(request, 'personal/main.html')
personal
-templates
--personal
---main.html
---content.html
在personal/view.py中:
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>
所以,当我启动服务器时,django只呈现“Hi everyone”,而不扩展内容块“My personal content”
为什么??
感谢您呈现了布局,而不是实际的模板。你的观点应该是:
from django.shortcuts import render
def index(request):
return render(request, 'personal/content.html')
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',
],
},
},
]
from django.shortcuts import render
def index(request):
return render(request, 'personal/content.html')