How to override and extend basic Django admin templates?

前端 未结 11 1077
长发绾君心
长发绾君心 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:34

    The best way to do it is to put the Django admin templates inside your project. So your templates would be in templates/admin while the stock Django admin templates would be in say template/django_admin. Then, you can do something like the following:

    templates/admin/change_form.html

    {% extends 'django_admin/change_form.html' %}
    
    Your stuff here
    

    If you're worried about keeping the stock templates up to date, you can include them with svn externals or similar.

提交回复
热议问题