Reputation: 375
I'm new Django user. In my new 1.9.4 project I created a new app called "personal". This is the app source tree:
personal
-templates
--personal
---main.html
---content.html
in personal/view.py:
from django.shortcuts import render
def index(request):
return render(request, 'personal/main.html')
in main.html
<!doctype html>
<html lang="en">
<body>
<p>Hi everyone!</p>
{% block content %}
{% endblock %}
</body>
</html>
in content.html
{% extends 'personal/main.html' %}
{% block content %}
<p>My personal content</p>
{% endblock %}
and finally my template settings in 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',
],
},
},
]
So when I start server, django renders only "Hi everyone" without extends the content block "My personal content".
Why? Thanks
Upvotes: 3
Views: 330
Reputation: 34922
You rendered the layout instead of the actual template. Your view should be:
from django.shortcuts import render
def index(request):
return render(request, 'personal/content.html')
Upvotes: 4