1

I am trying to modify the part {% block contentLeft%}. However, I can not change this part only. When I use {{super}} I get the full block but I can not change it.

I can not edit a block in a block.

I used includes, I tried to remove the block tags for the body however I can not modify the tag contentLeft, contentCenter, contentRight

I am also looking to change the name of modules in the administration page, do you have an idea? I changed the name of the models but I can not change the name of the "application"

Default value it's not a good solution (i post a sample exemple)

{% extends "base.html" %}
{% block title %}Ma page Date{% endblock %}

{% block body %}
  {{ block.super }}
  {% block contentLeft %}
    essai
  {% endblock %}
  {% block contentCenter %}
    centre
  {% endblock %}

  {% block contentRight %}
  droite
  {% endblock %}


{% endblock %}

{% load static %}
{% block body %}
  <body>
    {% block header %}
    {% include 'header.html' %}
    {% endblock %}

    <div class="container-fluid">
      <div class="row">
        <div class="col-md-2">
          {% block contentLeft %} Toto1 {% endblock %}
        </div>
        <div class="col-md-8">
          {% block contentCenter %} Toto2 {% endblock %}
        </div>
        <div class="col-md-2">
          {% block contentRight %} Toto3 {% endblock %}
        </div>
      </div>
    </div>

    {% block footer %}
      {% include 'footer.html' %}
    {% endblock %}

    <script src="{% static 'js/jquery-3.2.1.min.js' %}"></script>
    <script src="{% static 'js/bootstrap.js' %}"></script>
    <script src="{% static 'js/popper.min.js' %}"></script>
    <script src="{% static 'js/mdb.js' %}"></script>
  </body>
{% endblock %}

<!DOCTYPE html>
<html lang="fr">

{% block head %}
  {% include 'head.html' %}
{% endblock %}

{% block body %}
  {% include 'body.html' %}
{% endblock %}

</html>
  • It's hard to suggest an answer here because I think you need to simplify your structure. In the extending template, if you only want to change `{% block contentLeft %}` then keep it simple & don't do anything with the body block or anything else. Just modify the left block & see if that helps. – markwalker_ Mar 24 '18 at 21:13
  • This is just an example. In a project of higher complexity I will need to nest blocks – Quentin Bonnec Quentinb Mar 24 '18 at 21:20
  • Ok, well edit your question to better explain your code samples. The top sample extends `base.html` but it looks like (if it were my project) `base.html` would be the final sample which doesn't include `{% block contentLeft %}` so you can't do anything to that block because it's not in the inherited template. – markwalker_ Mar 24 '18 at 21:41
  • You dont understand, i post a example to explain simply my issue. I am trying to modify the part {% block contentLeft%}. However, I can not change this part only. When I use {{super}} I get the full block but I can not change it. The question is clear ... I want modify the block contentLeft in the page extends base.html – Quentin Bonnec Quentinb Mar 24 '18 at 21:47
  • Possible duplicate of [Django templates: overriding blocks of included children templates through an extended template](https://stackoverflow.com/questions/9996428/django-templates-overriding-blocks-of-included-children-templates-through-an-ex) – markwalker_ Mar 24 '18 at 21:59
  • No duplicate, the post propose include with default value. No resolve my issue. thank you for proposing your help i will wait to receive a good proposal or an explanation that will determine if my approach is correct. Good day to you – Quentin Bonnec Quentinb Mar 24 '18 at 22:06

0 Answers0