0

how can we hide a block in child template which is being rendered by paent template?

for ex: my parent template base.html contains-

<!DOCTYPE html>
<html lang="en">
....
<body>
{% block messages %}
      <div class="alert alert-{% if message.tags == 'error'%}danger{% else %}{{ message.tags }}{% endif %} alert-dismissible fade in" role="alert">
             {{message}}
      </div>
{% endblock %}
...
</body>
</html>

and I have inherited this base.html in login.html but I do not want to use {% block messages %} in login.html, any suggestions? Thanks in advance for any solution.

aditya k.
  • 35
  • 6

2 Answers2

3

You may override {% block messages %} in your login.html, like that:

login.html

{% extends "base.html" %}
{% block messages %}{% endblock %}
...
Nikita Zhuikov
  • 1,012
  • 8
  • 11
  • sorry but that didn't work, I am still able to view `base` `messages block` in the 'login.html` , any other solution, please? – aditya k. Jun 10 '21 at 16:07
  • Actually I can't understand why this solution dosen't work for you, may you display code of your login.html? – Nikita Zhuikov Jun 10 '21 at 16:17
  • thanks Nikita Zhuikov, actually I the `base.html` was including the `messages block` from another file as `{% include 'partials/_topbar_navigation.html' %}`, I moved the messages block to `base.html` . Now it is working. Thanks again. – aditya k. Jun 10 '21 at 16:45
1

As a side note, it is a better practice to have a base for login and registration which is different from your application base especially if you need users to login as alot of stuff won't show on these pages like the navbar.

Mohamed ElKalioby
  • 1,908
  • 1
  • 12
  • 13