D
D
DUDE2020-07-18 16:08:16
Django
DUDE, 2020-07-18 16:08:16

How to "block" a block in a template?

Hello everyone, I don’t even know if this can be called a problem, but I don’t quite understand how to solve it correctly. The template has a predescription block.

base.html

{% block predescription %}
  <div class="predescription">

  </div>
{% endblock %}


And from this template I am inherited in another.
some.html
{% extends '.../base.html' %}


{% block predescription %}

{% endblock %}


The predescription block has its own styles, and if I don’t write this block empty in the inherited template, then it will be displayed by default, which is logical. I do this in cases where I do not need to use the contents of this block.

I'm sure there is a more elegant way to "block" blocks in templates like this. Or can the predescription block be done differently?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-07-18
@stympel

This is a normal way, there is another option through the Include or inclusion tag to connect only when it is needed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question