Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difficulty overriding Django Admin template

I'm using Django 1.2.4 on Ubuntu 10.10. I'm trying to override the index.html template for the admin module. I've been following these instructions. I also looked at this question, but I'm still having difficulty.

The instructions say to create an admin directory in the templates directory:

templates/
    admin/
         index.html

I want to override a single block in the index.html. (Really, all I want to do is append some text to the end. Is there an easier way than copy/pasting the entire block and changing it?) (Update: Looks like {{block.super}} may help.)

To signal that I'm overriding, I put this at the top of my index.html:

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

Of course, that results in a stack overflow (from the terminal):

Exception RuntimeError: 'maximum recursion depth exceeded in __subclasscheck__' in <type 'exceptions.RuntimeError'> ignored

What is the correct way to do this? I tried a symlink per an answer on the linked question, but that resulted in the following:

me@mycomp:~/foo$ sudo ln -s /usr/local/lib/python2.6/dist-packages/django/contrib/admin/templates/ django_admin
[sudo] password for me: 
ln: creating symbolic link `django_admin': Protocol error

What am I doing wrong?

like image 901
Nick Heiner Avatar asked Feb 04 '11 18:02

Nick Heiner


People also ask

How do I override a Django template?

You can either put template overrides in your project's templates directory or in an application's templates directory. If you have app and project templates directories that both contain overrides, the default Django template loader will try to load the template from the project-level directory first.

Can we customize Django admin template?

Customizing the Django Admin ModelAdmin . Most of the customization you can do with the Django admin is done by modifying ModelAdmin , and you sure can modify it!

Is Django admin useful?

The Django admin application can use your models to automatically build a site area that you can use to create, view, update, and delete records. This can save you a lot of time during development, making it very easy to test your models and get a feel for whether you have the right data.

Is Django's admin interface customizable if yes then how?

To implement it in your project, make a new app in your Django project named products. Install this application, type product in the INSTALLED_APPS list in settings.py file. We will now make models in the products app. The model will be used throughout the tutorial to customize the Django Admin.


1 Answers

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...

like image 197
Aif Avatar answered Sep 22 '22 01:09

Aif