fasolo
fasolo

Reputation: 41

Extend django admin template

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.

Upvotes: 1

Views: 3446

Answers (2)

Nids Barthwal
Nids Barthwal

Reputation: 2419

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')],
}]

Upvotes: 1

Ohad the Lad
Ohad the Lad

Reputation: 1929

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.

Upvotes: 2

Related Questions