Cannot Extend Django 1.2.1 Admin Template

2019-06-09 11:45发布

I am attempting to override/extend the header for the Django admin in version 1.2.1. However when I try to extend the admin template and simply change what I need documented here: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-template), I run into a recursion problem.

I have an index.html file in my project's templates/admin/ directory that starts with

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

But it seems that this is referencing the local index file (a.k.a. itself) rather than the default Django copy. I want to extend the default Django template and simply change a few blocks. When I try this file, I get a recursion depth error.

How can I extend parts of the admin? Thanks.

SOLUTION: Rather than extending, I copied the files into my_templates_directory/admin/ and just edited them as I wished. This solution was acceptable, though not ideal.

3条回答
叛逆
2楼-- · 2019-06-09 12:10

Create a symlink to contrib/admin/templates/admin/ in your templates directory and use it in your {% extends %} statement.

cd /path/to/project/templates/
ln -s /path/to/django/contrib/admin/templates/admin/ django_admin

Now in your admin/index.html use {% extends "django_admin/index.html" %}

EDIT: Just realized that you're on windows... Not sure how to achieve the same results. Hopefully this still helps the folks on linux.

查看更多
Emotional °昔
3楼-- · 2019-06-09 12:12

SOLUTION: Rather than extending, I copied the files into my_templates_directory/admin/ and just edited them as I wished. This solution was acceptable, though not ideal.

查看更多
做个烂人
4楼-- · 2019-06-09 12:22

The contrib/admin/templates/admin path needs to go before the directory with your custom admin templates in your list of paths in TEMPLATE_DIRS in your settings.py

查看更多
登录 后发表回答