How to override and extend basic Django admin templates?

前端 未结 11 1008
长发绾君心
长发绾君心 2020-11-22 14:11

How do I override an admin template (e.g. admin/index.html) while at the same time extending it (see https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-r

11条回答
  •  -上瘾入骨i
    2020-11-22 14:23

    if you need to overwrite the admin/index.html, you can set the index_template parameter of the AdminSite.

    e.g.

    # urls.py
    ...
    from django.contrib import admin
    
    admin.site.index_template = 'admin/my_custom_index.html'
    admin.autodiscover()
    

    and place your template in /templates/admin/my_custom_index.html

提交回复
热议问题