Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize Django admin template

i tried customizing navbar like this

Base_site.html

 {% block nav-global %}
 <img class = "brand_img" src = "{% static 'images/ic_launcher.png'%}" 
    width = "50" height = "50" alt = "logo">
 {%block branding%}    

  {% endblock %}
  <div class = "head">
    <h1 id = "name">Admin Dashboard</h1>
  </div>    
{% endblock %}

which looks like this

admin page

now i try to add header for login page inside {%block branding%}

login page

but if i add inside branding block it is displayed in navbar also and if i try to add both image and header in branding block image is displayed login page header.

how to add different titles for navbar and login page header?

like image 272
Ashok Avatar asked Nov 30 '22 22:11

Ashok


1 Answers

This can be achieved pretty easily.

Inside your templates folder, you should have created an admin subfolder. Inside there, you should place the files base_site.html and login.html.

Contents of base_site.html:

{% extends 'admin/base_site.html' %}

{% load static %}

{% block branding %}
    <div class="head">
        <h1 id="name">Admin Dashboard</h1>
    </div>
{% endblock %}

{% block nav-global %}
    <img class="brand_img" src="{% static 'images/ic_launcher.png'%}" width="50" height="50" alt="logo">
{% endblock %}

Contents of login.html:

{% extends 'admin/login.html' %}

{% block branding %}
    <div class="head">
        <h1 id="name">Custom header text for LOGIN screen only</h1>
    </div>
{% endblock %}

Below is the correct project structure:

project/
    myapp/
    myapp2/
    project/
    templates/
        admin/
            base_site.html
            login.html
    manage.py

Please note the extends inside each html template you want to override. It's vital. For more info take a look at the docs.

like image 94
nik_m Avatar answered Dec 06 '22 20:12

nik_m