For example, the user can overwrite the entire navbar if the header was
put inside `{% block header %}` simply by extending the template.
Refer to this conversation [https://groups.google.com/g/django-
developers/c/Q8I-0-2Sn4M] (point 2) for the full discussion
--
Ticket URL: <https://code.djangoproject.com/ticket/32324>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => Muskan Vaswan
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:1>
* status: assigned => closed
* resolution: => invalid
Comment:
> For example, the user can overwrite the entire navbar if the header was
put inside {% block header %} simply by extending the template.
The navigation sidebar is already in a separate block `nav-sidebar` and
use a separate template, so it's easy to customize, see
[https://code.djangoproject.com/ticket/31856?cnum_edit=1#comment:1
comment]. Also, `header` already contains blocks for each element so I
don't see how adding another `block` around existing blocks can increase
flexibility.
--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:2>
Comment (by Muskan Vaswan):
That was an example... Also adding the entire header inside a block
improves flexibility as it allows the user to change the entire topbar in
one go rather changing singular elements. Not to mention currently if the
user wants to make an entirely new topbar... ideally making the old one
disappear entirely they would have to override and extend two files, that
is, base_site.html for (branding block) and base.html (for the user_tools
block) both and it still doesn't entirely dissapear. Which could simply be
accomplished by adding a block for the entire header and the user could
simply extend the base.html and `{% block header %}{% endblock %}`.
Another example is if the user wants to change the add_url for a
particular model having more blocks would be very helpful.
Replying to [comment:2 Mariusz Felisiak]:
> > For example, the user can overwrite the entire navbar if the header
was put inside {% block header %} simply by extending the template.
>
> The navigation sidebar is already in a separate block `nav-sidebar` and
use a separate template, so it's easy to customize, see
[https://code.djangoproject.com/ticket/31856?cnum_edit=1#comment:1
comment]. Also, `header` already contains blocks for each element so I
don't see how adding another `block` around existing blocks can increase
flexibility.
--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:3>
* resolution: invalid => needsinfo
Comment:
Ticket described as ''"adding more blocks"'' cannot be accepted, it's too
generic. You need to describe a concrete issue and use case. Maybe you
should [https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#set-up-
your-projects-admin-template-directories "Set up your projects admin
template directories"] for your use case.
> Another example is if the user wants to change the add_url for a
particular model having more blocks would be very helpful.
I don't think that templates are appropriate place for such logic.
--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:4>
Old description:
> 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.
>
> For example, the user can overwrite the entire navbar if the header was
> put inside `{% block header %}` simply by extending the template.
>
> Refer to this conversation [https://groups.google.com/g/django-
> developers/c/Q8I-0-2Sn4M] (point 2) for the full discussion
New description:
=== Use case
Allowing the user to overwrite the Top Navigation Bar od the admin page.
=== Existing method
to Overwrite the top nav-bar without having to overwrite the entire
template of base.html, the user currently has to add the
{{{
{% extends "admin/base_site.html" %}
{% load static %}
{% block branding %}
{% endblock %}
}}}
to admin/base_site.html and`
{{{
{% extends "admin/base.html" %}
{% load static %}
{% block usertools %}
{% endblock %}
}}}
to admin/base.html.
No other method, other than overwriting the entire template exists.
=== Issue with Existing method
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
(Image attached)
2. The user must extend two separate files to even make this happen.
=== Solution
The simple solution is to wrap the entire header class using {% block ...
%}. So the final django/admin/base.html would have:
{{{
<!-- Header -->
{% block header %}
<div id="header">
...
</div>
{% endblock %}
<!-- END Header -->
}}}
=== Final Result
The user will be able to overwrite the default blue-green nav-bar
*entirely* by adding
{{{
{% extends "admin/base.html" %}
{% load static %}
{% block header %}
{% endblock %}
}}}
to admin/base.html.
--
Comment (by Muskan Vaswan):
In consideration of that, I wrote a more specific and comprehensive Issue.
I hope this makes it more clear.
--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:5>
* Attachment "Screen Shot 2021-01-06 at 5.02.36 PM.png" added.
* status: closed => new
* resolution: needsinfo =>
Comment:
Thanks for the more detailed info. I will reopen to triage again.
--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:6>
* stage: Unreviewed => Accepted
Comment:
Hmmm. I'm a bit sceptical that very many people want to remove the header
entirely, but I agree that a single block would make that feasible.
> 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
Query: an amount of CSS resolves that no?
--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:7>
Old description:
> === Use case
> Allowing the user to overwrite the Top Navigation Bar od the admin page.
>
> === Existing method
>
> to Overwrite the top nav-bar without having to overwrite the entire
> template of base.html, the user currently has to add the
>
> {{{
> {% extends "admin/base_site.html" %}
> {% load static %}
> {% block branding %}
> {% endblock %}
> }}}
>
> to admin/base_site.html and`
>
> {{{
> {% extends "admin/base.html" %}
> {% load static %}
> {% block usertools %}
> {% endblock %}
> }}}
> to admin/base.html.
> No other method, other than overwriting the entire template exists.
>
> === Issue with Existing method
>
> 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
> (Image attached)
>
> 2. The user must extend two separate files to even make this happen.
>
> === Solution
>
> The simple solution is to wrap the entire header class using {% block ...
> %}. So the final django/admin/base.html would have:
>
> {{{
> <!-- Header -->
> {% block header %}
> <div id="header">
> ...
> </div>
> {% endblock %}
> <!-- END Header -->
>
> }}}
>
> === Final Result
> The user will be able to overwrite the default blue-green nav-bar
> *entirely* by adding
>
> {{{
> {% extends "admin/base.html" %}
> {% load static %}
> {% block header %}
> {% endblock %}
> }}}
> to admin/base.html.
New description:
=== Use case
Allowing the user to overwrite the Top Navigation Bar od the admin page.
=== Existing method
to Overwrite the top nav-bar without having to overwrite the entire
template of base.html, the user currently has to add the
{{{
{% extends "admin/base_site.html" %}
{% load static %}
{% block branding %}
{% endblock %}
}}}
to admin/base_site.html and`
{{{
{% extends "admin/base.html" %}
{% load static %}
{% block usertools %}
{% endblock %}
}}}
to admin/base.html.
No other method, other than overwriting the entire template exists.
=== Issue with Existing method
1. Even after doing the above, the top-bar doesn't entirely disappear due
to the CSS applied on the <div> with the id of header
(Image attached)
2. The user must extend two separate files to even make this happen.
=== Solution
The simple solution is to wrap the entire header class using {% block ...
%}. So the final django/admin/base.html would have:
{{{
<!-- Header -->
{% block header %}
<div id="header">
...
</div>
{% endblock %}
<!-- END Header -->
}}}
=== Final Result
The user will be able to overwrite the default blue-green nav-bar
*entirely* by adding
{{{
{% extends "admin/base.html" %}
{% load static %}
{% block header %}
{% endblock %}
}}}
to admin/base.html.
--
Comment (by Muskan Vaswan):
Replying to [comment:7 Carlton Gibson]:
> Hmmm. I'm a bit sceptical that very many people want to remove the
header entirely, but I agree that a single block would make that feasible.
>
> > 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
>
> Query: an amount of CSS resolves that no?
Yes, adding CSS to make would surely make it disappear, but I'm not sure
if that would be the best way to do it, but again, that's just what I
think.
About the first point, I have come across many occasions when I needed to
replace the admin top-nav and personally, I don't think its that uncommon
to have a themed top-bar that you want to use throughout the website.
At the same time, I agree, it's not a pressing issue by any means.
I guess it's just a matter of deciding whether making something like this
more convenient for the user justifies adding another block...
--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:8>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:9>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:10>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"ab7478d1d4aeaa816cd723793ae9e8325ad11c33" ab7478d]:
{{{
#!CommitTicketReference repository=""
revision="ab7478d1d4aeaa816cd723793ae9e8325ad11c33"
Fixed #32324 -- Added template block to override the admin site header.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32324#comment:11>