How to override and extend basic Django admin templates?

前端 未结 11 1013
长发绾君心
长发绾君心 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条回答
  •  执念已碎
    2020-11-22 14:32

    With django 1.5 (at least) you can define the template you want to use for a particular modeladmin

    see https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#custom-template-options

    You can do something like

    class Myadmin(admin.ModelAdmin):
        change_form_template = 'change_form.htm'
    

    With change_form.html being a simple html template extending admin/change_form.html (or not if you want to do it from scratch)

提交回复
热议问题