定制Django Admin首页
在目录templates/admin文件夹在重载index.html文件,对下面的默认文件内容进行修改就行
下面这个django admin默认的index.html:
{% extends "admin/base_site.html" %}
{% load i18n %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% load adminmedia %}{% admin_media_prefix %}css/dashboard.css" />{% endblock %} #用于写css box
{% block coltype %}colms{% endblock %}
{% block bodyclass %}dashboard{% endblock %}
{% block breadcrumbs %}{% endblock %}
{% block content %}
<p id="content-main">
{% if app_list %} #显示各个modeladmin{% if app_list and false%}不显示可定制这部分
{% for app in app_list %}
<p class="module">
<table summary="{% blocktrans with app.name as name %}models available in the {{ name }} application.{% endblocktrans %}">
<caption><a href="{{ app.app_url }}" class="section">{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</a></caption>
{% for model in app.models %}
<tr>
{% if model.perms.change %}
<th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
{% else %}
<th scope="row">{{ model.name }}</th>
{% endif %}
{% if model.perms.add %}
<td><a href="{{ model.admin_url }}add/" class="addlink">{% trans 'add' %}</a></td>
{% else %}
<td> </td>
{% endif %}
{% if model.perms.change %}
<td><a href="{{ model.admin_url }}" class="changelink">{% trans 'change' %}</a></td>
{% else %}
<td> </td>
{% endif %}
</tr>
{% endfor %}
</table>
</p>
{% endfor %}
{% else %}
<p>{% trans "you don't have permission to edit anything." %}</p>
{% endif %}
</p>
{% endblock %}
{% block sidebar %} #操作,历史操作,
<p id="content-related">
<p class="module" id="recent-actions-module">
<h2>{% trans 'recent actions' %}</h2>
<h3>{% trans 'my actions' %}</h3>
{% load log %}
{% get_admin_log 10 as admin_log for_user user %}
{% if not admin_log %}
<p>{% trans 'none available' %}</p>
{% else %}
<ul class="actionlist">
{% for entry in admin_log %}
<li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}">
{% if entry.is_deletion %}
{{ entry.object_repr }}
{% else %}
<a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
{% endif %}
<br/>
{% if entry.content_type %}
<span class="mini quiet">{% filter capfirst %}{% trans entry.content_type.name %}{% endfilter %}</span>
{% else %}
<span class="mini quiet">{% trans 'unknown content' %}</span>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
</p>
</p>
{% endblock %}