Sunday, February 27, 2011

Extend admin template without copying the whole template

Hi all,

I want to add a language switcher below the breadcrumb to all my django admin pages.

Therefore I created templates/admin/base.html in my project. However I don't want to copy the whole original base.html and add my changes - this would defeat the DRY principle and it would be a maintenance nightmare whenever I update to the latest django version.

So I tried the obvious:

{% extends "admin/base.html" %}
{% block breadcrumb %}
[old breadcrumb code]
[my additional code]
{% endblock %}

And of course the obvious error happened: The template tries to extend itself. Couldn't the system be smart enough and recognize that it is trying to import itself and then search for another template to extend at the next available template loader in line? As in: Whoops, I'm trying to extend myself when using base.html from the project's file system... ok let's see if I can find admin/base.html in the python path or in the eggs...

Is there any other fancy trick or workaround to accomplish this? I believe that enhancing global admin templates should be something that is a very common usecase, isn't it?

Best regards,
Martin

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment