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 | |
| 7 | to 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 | |
| 16 | to 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. |
| 25 | No other method, other than overwriting the entire template exists. |
| 26 | |
| 27 | === Issue with Existing method |
| 28 | |
| 29 | 1. 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 | |
| 32 | 2. The user must extend two separate files to even make this happen. |
| 33 | |
| 34 | === Solution |
| 35 | |
| 36 | The 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 |
| 50 | The 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 | }}} |
| 59 | to admin/base.html. |