Change attributes of html tags from a template that inherits the content from a base.html file

0

I have a template base.html of which the rest of my templates expand it by means of the label extends , an example of the code of the file base.html is the following:

{% load static %}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>{% block title %}{% endblock %}</title>
<body class="hold-transition skin-blue sidebar-mini">
    {% block content %}
    {% endblock %}
</body>
</html>

As I am using bootstrap I must define certain classes to some html tag. My problem is the following I would like that in a only template, for example, login.html can overwrite the class of the body to be affected only in that template, the code of the file login.html is:

 {% extends 'base.html' %}
 {% load static %}
 {% block title %} Título {% endblock %}
 {% block content %}
       ....
 {% endblock %}
    
asked by mihael 26.02.2018 в 20:45
source

1 answer

1

In the base.html you could put:

<body class="{% block body_class%}hold-transition skin-blue sidebar-mini{% endblock %}">

and in the login.html you add:

{% block body_class%}login_body_class{% endblock %}

The resulting html in the login.html will be:

<body class="login_body_class">

In other templates if you do not add that block it will look like this:

<body class="hold-transition skin-blue sidebar-mini">
    
answered by 26.02.2018 / 23:49
source