如何在同一个django项目中为2个应用程序使用2个不同的change_list.html [英] How to use 2 different change_list.html for 2 applications in the same django project

查看:83
本文介绍了如何在同一个django项目中为2个应用程序使用2个不同的change_list.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在django项目中有2个应用程序。我想在2个不同应用程序的change_list.html中添加不同的小部件。在settings.py中,在两个应用程序中的模板的admin目录中添加change_list.html之后,
TEMPLATE_DIRS =(
/ home / path / project / application1 / templates,
/ home / path / project / application2 / templates,



我注意到,所考虑的change_list.html模板来自应用程序1。只有当我发表评论时,才会考虑应用程序2中的模板。怎么走?我想让他们两个不同的应用被考虑。请建议。

解决方案

阅读覆盖管理模板的部分: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates (更具体地说 https://docs.djangoproject.com/en/dev/ref/contrib/admin/#templates-which-may-be-overridden-per-app-or-model )在 admin / application1 中放置 change_list.html

<在 TEMPLATE_DIRS 解析的其中一个文件夹中,或者一个模板加载程序和该模板将仅为 application1 提供。



您当前的代码总是告诉django在第二个路径上优先考虑匹配。


I have 2 applications in the django project. I want to add different widgets in the change_list.html for the 2 different applications. In settings.py, after adding the change_list.html in the admin directory of the templates in both the applications respectively as, TEMPLATE_DIRS = ( "/home/path/project/application1/templates", "/home/path/project/application2/templates",
)

I notice that the change_list.html template considered is from the application1. Only if I comment it, the template from application2 is considered. How to go about? I want both of them to be considered for the 2 different applications. Please suggest.

解决方案

Read the section on overriding admin templates: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates (more specifically https://docs.djangoproject.com/en/dev/ref/contrib/admin/#templates-which-may-be-overridden-per-app-or-model)

Place your change_list.html in admin/application1 in one of the folders parsed by TEMPLATE_DIRS or one of the template loaders and that template will be served only for application1.

Your current code is always telling django to prioritize matches on the first path over the second.

这篇关于如何在同一个django项目中为2个应用程序使用2个不同的change_list.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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