且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何覆盖和扩展基本的Django管理模板?

更新时间:2023-11-20 20:19:28

我有一年半以前有同样的问题,我发现一个很好的 djangosnippets.org上的模板加载器,这使得这很容易。它允许您在特定应用程序中扩展模板,使您能够创建自己的 admin / index.html ,从admin应用程序扩展admin / index.html模板。像这样:

I had the same issue about a year and a half ago and I found a nice template loader on djangosnippets.org that makes this easy. It allows you to extend a template in a specific app, giving you the ability to create your own admin/index.html that extends the admin/index.html template from the admin app. Like this:

{% extends "admin:admin/index.html" %}

{% block sidebar %}
    {{block.super}}
    <div>
        <h1>Extra links</h1>
        <a href="/admin/extra/">My extra link</a>
    </div>
{% endblock %}

我已经给出了一个关于如何使用这个我的网站上的博客文章中的模板加载器。

I've given a full example on how to use this template loader in a blog post on my website.