Hi Josh. 

This was added in Django 1.9 here 
https://github.com/django/django/commit/fc2147152637e21bc73f991b50fa06254af02739

It leverages the extends tag, re-using the same template name: 

    # myapp/templates/admin/base.html
    {% extends "admin/base.html" %}
    {% block footer %}this site is restricted, blah blah legal text blah{% 
endblock %}

So as long as myapp/templates are loaded before contrib.admin's then it you 
should see the result you're after. 

#15053 <https://code.djangoproject.com/ticket/15053> references 
django-overextends as the influence. 


Kind Regards,

Carlton



On Tuesday, 16 June 2020 07:03:53 UTC+2, Josh Smeaton wrote:
>
> Something that has bugged me for awhile is the requirement to copy and 
> paste an entire template when you would just like to override a single 
> block. This arises mostly when overriding admin templates, like 
> `admin/base.html`.
>
> In my ideal world, I'd be able to do something like this:
>
>     # myapp/templates/admin/base.html
>     {% override "admin/base.html" %}
>     {% block footer %}this site is restricted, blah blah legal text blah{% 
> endblock %}
>
>
> And then the template loading system would find the next `admin/base.html` 
> in the chain and use my overrides.
>
> There is prior art too. https://pypi.org/project/django-apptemplates/ 
> allows you to override a template from a specific app using this syntax:
>
>     # myapp/templates/admin/base.html
>     {% extends "admin:admin/base.html" %}
>     {% block footer %}this site is restricted, blah blah legal text blah{%
>  endblock %}
>
>
> I think this kind of functionality should be included within Django 
> itself. If others agree, should there be a new name such as override, or 
> would overloading extends be good enough?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/e0fe802f-f673-471d-ac4d-8e4c613a0cf8o%40googlegroups.com.

Reply via email to