Django Admin:为两个管理站点使用不同的模板
我有一个具有两个不同管理站点的 Django 项目(如 文档 )
我想为每个人都有不同的自定义模板。 我知道如何通过将 html 文件放入 myproject/templates/admin/ 目录来覆盖自定义模板。 但是,两个管理站点都使用这些模板!
我不明白如何指定另一组自定义模板。
理想情况下,我希望有:
# For first admin site
myproject/templates/admin-a/
base.html
base_site.html
和:
# For second admin site
myproject/templates/admin-b/
base.html
base_site.html
I've a Django project with two different admin-site (as described in documentation )
I would like to have different custom template for each of them.
I know how to override custom template, by putting html files in myproject/templates/admin/ directory.
However, both admin-site use those templates !
I don't understand how to specify another set of custom templates.
Ideally, I would like having:
# For first admin site
myproject/templates/admin-a/
base.html
base_site.html
and:
# For second admin site
myproject/templates/admin-b/
base.html
base_site.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个选项是有两个
ModelAdmin
类,一个派生自第二个类,并带有一些定义模板的附加参数,这是管理代码的一部分:可以在您的管理类中设置上述变量。
第二种方法是将基本模板名称传递到模板中,然后使用此(变量)作为
extends
模板标记的参数。 此处的文档。第三个选项是有两个实例代码运行,但有两个配置具有不同的设置变量
TEMPLATE_DIRS
,第一个例如:第二个
在这里拥有两个模板目录会给您一个后备选项,因此您将只定义那些不同的模板。
第三个选项最容易实现(无需更改代码),但它需要 2 个独立的实例同时工作(消耗更多的系统资源)。
first option will be to have two
ModelAdmin
classes, one derived from second one, with some additional parameters defining templates, here is part of the admin code:above variables can be set in your admin class.
second way is to pass a base template name into the template, and then use this (variable) as a parameter to the
extends
template tag. Documentation here.third option wil be to have a two instances of code running, but with two configs with different setting variable
TEMPLATE_DIRS
, first one e.g.:second
Having both template dirs here gives you an fallback option, so you will define only those templates which are different.
Third option is easiest to implement (no change to the code) but it requires 2 separated instances working at the same time (more system resources consumed).