Django Admin: using different templates for two admin site

爱⌒轻易说出口 提交于 2019-12-06 01:54:02

问题


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

Any ideas ?

Thanks, Stéphane


回答1:


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:

# Custom templates (designed to be over-ridden in subclasses)
add_form_template = None
change_form_template = None
change_list_template = None
delete_confirmation_template = None
delete_selected_confirmation_template = None
object_history_template = None

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

TEMPLATE_DIRS = ('templates-a',)

second

TEMPLATE_DIRS = ('template-b', 'template-a')

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



来源:https://stackoverflow.com/questions/5420990/django-admin-using-different-templates-for-two-admin-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!