L
L
ldmitriy2019-10-11 10:42:03
Jinja
ldmitriy, 2019-10-11 10:42:03

Jinja2. What is the difference between extends and include?

one inherits, the other includes.
I didn't see any difference in practice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2019-10-11
@ldmitriy

Of course, there is a difference, and a significant one. Extends extends an existing template, and include adds a piece of the template in the right place.
Let's imagine a situation with a sufficiently large template, where only part of the page needs to be changed. The base template looks something like this

<!-- parent -->
{%block заголовок%}
{%block левый_блок%}
{%block правый_блок%}
{%block тело%}
{%block подвал%}

If you inherit from this template, it will look something like this
<!-- chlid -->
{% extends parent %}
{%block левый_блок %}
{%block тело %}

Otherwise, we would have to connect all other blocks with inclusions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question