开发者

Django Admin: using different templates for two admin site

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 t开发者_如何学Gohose 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜