[Solved]-Difficulty overriding Django Admin template

13👍

The recursion error is because you’re extending the admin/index.html with itself.

You can either:

  • copy the entire admin/index.html template in your templates/admin/ directory, and it will replace the default template with yours
  • override the index.html per app or model, as explained here

I know this is late after the question, but you know, google traveling…

👤Aif

7👍

Amend settings.py with an extra template folder, for example:

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    "/home/mysite/webapps/django/myproject/templates",
    "/home/mysite/webapps/django/lib/python2.7/django/",  # extra folder
)

Then in myproject/templates/admin add your own index.html like:

{% extends "contrib/admin/templates/admin/index.html" %}

{% block branding %}
    <h1 id="site-name">Administration for TheLittleButtonCo</h1>
{% endblock %}

Variations are possible, obviously. This works on Django 1.3.1 final

1👍

Not sure if you found the answer, but you need to change

{% extends "admin/index.html" %}

to

{% extends "admin/base_site.html" %}

as that is what the original index.html page overwrites. Because the Django system searches your templates folder before using the default admin one, so in this case it finds the admin/index.html in your templates, then it’s trying to extend itself with the extend (hence the recursion error).

For reference you can customise the base_site.html in you templates too, it extends base.html. The best thing to do is copy the original from:

/usr/local/lib/python2.6/dist-packages/django/contrib/admin/templates/

and paste it into your templates folder as a starting point

1👍

I use an extra package, called django-smart-extends

👤dotz

Leave a comment