1

I'm trying to add a custom button in change_list django admin page next to the add object in the top of the page.

{% extends "admin/change_list.html" %} 
{% load i18n %} 
{% block object-tools-items %}
{{ block.super }}
<li>
    <button class="" href="...">Click Here!</button>
</li>
{% endblock %}

I followed a lot of tutorials but with no success. I have 'APP_DIRS': True, in my settings.py and my project is like:

project/
    app/
        templates/
            change_list.html
            custom_template.html

The custom_template.html is an Action in change_list, and it works. Am i missing something?

EDIT:

Already tried:

project/app/templates/admin/change_list.html project/app/templates/app/admin/change_list.html

Didn't work either.

fasolo
  • 41
  • 1
  • 9
  • Based on this question, it looks like you forgot to specify the app name in the extend tag http://stackoverflow.com/questions/6583877/how-to-override-and-extend-basic-django-admin-templates – Wonskcalb Nov 26 '16 at 14:18

2 Answers2

2

change_list.html override file lives in this location:

project/app/templates/admin/app/change_list.html

You almost got it . :)

Also u may use django-debug-toolbar and get the actual templates that were uploaded at the browser side.

Ohad the Lad
  • 1,889
  • 1
  • 15
  • 24
1

Change you template location to project/templates/admin/change_list.html

In template 'change_list.html' write

{% extends 'admin/base.html' %}
{% block branding %}
<h1 id="site-name">My custom Admin</h1>
{% endblock %}

and in setting.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 
TEMPLATES = [
{
    'DIRS': [os.path.join(BASE_DIR, 'templates')],
}]
Nids Barthwal
  • 2,205
  • 20
  • 12