L
L
Legalas612016-09-11 01:10:20
Django
Legalas61, 2016-09-11 01:10:20

Why isn't extends django output?

Can't extend base.html template with header.html template Base.html
content

<div id="main-container">
  <!-- HEADER -->
  {% block header %}{% endblock %}
  <!-- END HEADER -->
</div>

header.html content
{% extends "blog/base.html" %}
{% block header %}
<header id="header">
***
</header>
{% endblock %}

Views.py content
from django.shortcuts import render
from django.utils import timezone
from .models import Post
from django.shortcuts import render, get_object_or_404

def post_list(request):
    posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
    return render(request, 'blog/index.html', {'posts': posts})

def post_detail(request, pk):
        post = get_object_or_404 (Post, pk=pk)
        return render(request, 'blog/base.html', {'post': post})

def header(request):
    return render (request, 'blog/header.html')

The output in the browser is the following code:
<div id="main-container">
  <!-- HEADER -->

  <!-- END HEADER -->

Why can't I expand the template? Through {% include "blog/header.html" %}- it works, but not through extends. I am using Django 1.10.1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2016-09-11
@dimonchik2013

these are different things
stackoverflow.com/questions/2863695/include-vs-ext...
stackoverflow.com/questions/2323020/django-extends
... ...
djbook.ru/rel1.9/ref/templates/builtins.html#std:t...

S
sim3x, 2016-09-11
@sim3x

0. Wrong paths
1.render (

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question