简体   繁体   中英

Two instances of django admin site - templates

for some reason I need to have two different instances of Django Admin Site in my project - default admin site and an instance of class inheriting from AdminSite.

So I created a class MyAdminSite(AdminSite)

Then I wrote something like:

my_admin_site = MyAdminSIte(name='myadmin')

Then I added proper entry in urls.py.

Everything works fine.

But now i want to customize some templates.
In settings.py:

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)

Then I created directories: /PROJECTDIR/templates/admin and /PROJECTDIR/templates/myadmin

The thing is, I simply cannot extend/override templates in 'myadmin' django admin site. For example, if I add, let's say an empty 'base_site.html' into /templates/admin/, then both admin sites becomes blank.

But when I add same file into /templates/myadmin/, nothing happenes.

Any tips?

You can override class variables of AdminSite to specify different templates:

app_index_template = None
login_template = None
logout_template = None
password_change_template = None
password_change_done_template = None

You can also override class variables of ModelAdmin to specify different templates:

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

For example:

class MyAdminSite(AdminSite):
    app_index_template = "my/new/admin/app_index.html"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM