Changes between Initial Version and Version 5 of Ticket #32324


Ignore:
Timestamp:
Jan 6, 2021, 6:19:58 AM (4 years ago)
Author:
Muskan Vaswan
Comment:

In consideration of that, I wrote a more specific and comprehensive Issue. I hope this makes it more clear.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32324

    • Property Owner changed from nobody to Muskan Vaswan
    • Property Status newclosed
    • Property Resolutionneedsinfo
    • Property Summary Adding more blocks to the contrib.admin siteWrapping the header in base.html of contrib.abmin in {% blocks %}.
  • Ticket #32324 – Description

    initial v5  
    1 The Django admin template can be overridden and extended by the user. However, flexibility to customize the admin page can be increased by putting larger chunks of code inside a `{% block  ... %}... {% endblock %}`. This will be useful as it will allow the user to completely rewrite an entire segment of the page without having to override smaller elements or the entire template.
    21
    3 For example, the user can overwrite the entire navbar if the header was put inside `{% block header %}` simply by extending the template.
     2=== Use case
     3Allowing the user to overwrite the Top Navigation Bar od the admin page.
    44
    5 Refer to this conversation [https://groups.google.com/g/django-developers/c/Q8I-0-2Sn4M] (point 2) for the full discussion
     5=== Existing method
     6
     7to Overwrite the top nav-bar without having to overwrite the entire template of base.html, the user currently has to add the
     8
     9{{{
     10{% extends "admin/base_site.html" %}
     11{% load static %}
     12{% block branding %}
     13{% endblock %}
     14}}}
     15 
     16to admin/base_site.html and`
     17
     18{{{
     19{% extends "admin/base.html" %}
     20{% load static %}
     21{% block usertools %}
     22{% endblock %}
     23}}}
     24 to admin/base.html.
     25No other method, other than overwriting the entire template exists.
     26
     27=== Issue with Existing method
     28
     291. Even after doing the above the top-bar doesn't entirely disappear dude to the CSS applied on the <div> with the id of header
     30(Image attached)
     31
     322. The user must extend two separate files to even make this happen.
     33
     34=== Solution
     35
     36The simple solution is to wrap the entire header class using {% block ... %}. So the final django/admin/base.html would have:
     37
     38{{{
     39    <!-- Header -->
     40    {% block header %}
     41    <div id="header">
     42        ...
     43    </div>
     44    {% endblock %}
     45    <!-- END Header -->
     46
     47}}}
     48
     49=== Final Result
     50The user will be able to overwrite the default blue-green nav-bar *entirely* by adding
     51
     52
     53{{{
     54{% extends "admin/base.html" %}
     55{% load static %}
     56{% block header %}
     57{% endblock %}
     58}}}
     59to admin/base.html.
Back to Top