Django管理模板覆盖不起作用 [英] Django admin template override not working

查看:84
本文介绍了Django管理模板覆盖不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Django 1.6.11

Django 1.6.11

应用程序结构如下:

my_project/
     |-- new_app/
     |-- templates/

在我的配置中:

TEMPLATE_ROOT = os.path.join(BASE_ROOT, 'templates/')
TEMPLATE_DIRS = (
    TEMPLATE_ROOT,
)
INSTALLED_APPS = (
    'django.contrib.admin',
    ...
    'new_app',
)

我也尝试过列出 new_app contrib.admin 并没有帮助。

I've also tried listing new_app before contrib.admin and that didn't help.

当我复制 venv / django时/contrib/admin/templates/admin/change_list.html 到我的 /templates/admin/new_app/change_list.html 我看不到我的

When I copy venv/django/contrib/admin/templates/admin/change_list.html to my /templates/admin/new_app/change_list.html I don't see my customizations show up.

my_project/
     |-- new_app/
     |-- templates/
         |-- admin/
             |-- new_app/
                 |-- change_list.html

当我移动cha时nge_list.html向上一级,因此它位于admin路径下,更改显示就很好了:

When I move change_list.html up one level so it's under the admin path, the changes show up just fine:

my_project/
     |-- new_app/
     |-- templates/
         |-- admin/
             |-- change_list.html
             |-- new_app/   (now an empty folder)

...但是,这当然意味着我的更改将影响每个管理页面,而不仅仅是我正在尝试修改的应用程序。

... but of course that would mean my changes are going to affect every admin page, not just for the app I'm trying to modify.

我已将其添加到admin.py中应用程序的唯一模型中:

I've added this to the app's only model within admin.py:

class MyModelAdmin(reversion.VersionAdmin):
    change_list_template = 'admin/new_app/change_list.html'

...这给了我一些我需要的东西,但是我还需要change_list_results.html,并且对此没有ModelAdmin替代。

... this gives me some of what I need, but I also need change_list_results.html and there's no ModelAdmin override for that.

我正在遵循 readthedocs 在第2节中.4.8在第31页,但是我似乎没有任何运气。

I'm following the documentation guide found at readthedocs in section 2.4.8 on page 31, but I don't seem to be having any luck.

推荐答案

当多个应用程序提供不同版本的在相同资源(模板,静态文件,管理命令,转换)相同的情况下,INSTALLED_APPS中首先列出的应用程序具有优先权。请参阅文档

When several applications provide different versions of the same resource (template, static file, management command, translation), the application listed first in INSTALLED_APPS has precedence. See docs.

更改:

INSTALLED_APPS = (
    'django.contrib.admin',
    ...
    'new_app',
)

收件人:

INSTALLED_APPS = (
    'new_app',
    'django.contrib.admin',
    ...
)

您在<$现在应该在 contrib.admin 中的模板之前找到c $ c> new_app 。

Your templates in new_app should now be found before the templates in contrib.admin.

这篇关于Django管理模板覆盖不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆