Django admin后台默认模板文件解读
admin的默认模板位于django/contrib/admin/templates/admin/文件下,文件结构接对应解读说明如下:
auth/user
add_form.html
change_password.html
edit_inline
stacked.html
tabular.html
includes
fieldset.html
object_delete_summary.html
widgets
clearable_file_input.html
date.html
foreign_key_raw_id.html
many_to_many_raw_id.html
radio.html
related_widget_wrapper.html
split_datetime.html
time.html
url.html
404.html
500.html
actions.html
app_index.html
app_list.html
base.html
base_site.html
change_form.html
change_form_object_tools.html
change_list.html
change_list_object_tools.html
change_list_results.html
color_theme_toggle.html
date_hierarchy.html
delete_confirmation.html
delete_selected_confirmation.html
filter.html
index.html
invalid_setup.html
login.html
nav_sidebar.html
object_history.html
pagination.html
popup_response.html
prepopulated_fields_js.html
search_form.html
submit_line.html
页面内部分标签说明
{% block title %}{% endblock %}#站点标题
{% block stylesheet %}{%%20static "admin/css/base.css" %}{% endblock %}"#基础css路径
{% block dark-mode-vars %}
<link rel="stylesheet" href="{%%20static "admin/css/dark_mode.css" %}">
<script src="{%%20static "admin/js/theme.js" %}" defer></script>
{% endblock %}#主题静态文件路径
{% if not is_popup and is_nav_sidebar_enabled %}
{% endif %}#is_popup判断
{% block extrastyle %}{% endblock %}#额外css
{% block extrahead %}{% endblock %}#额外head设置
{% block responsive %}{% endblock %}#请求判断
{% block blockbots %}{% endblock %}#搜索引擎优化配置
{% if is_popup %}popup {% endif %}{% block bodyclass %}{% endblock %}"#body class设置
{%%20if not is_popup %}
<!-- Header -->
#头部开始
{% block header %}
{% block branding %}{% endblock %}#标签页面
{% block usertools %}
{%%20if has_permission %}
{% block welcome-msg %}
{% endblock %}#欢迎词加注
{% block userlinks %}
{%%20if site_url %}
{%%20endif %}#站点链接
{%%20if user.is_active and user.is_staff %}
{% url 'django-admindocs-docroot' as docsroot %}
{%%20if docsroot %}
#文档链接
{%%20endif %}
{%%20endif %}
{%%20if user.has_usable_password %}
#修改密码
{%%20endif %}
{% endblock %}#链接
{%%20endif %}#权限判断
{% endblock %}#页头顶部
{% block nav-global %}{% endblock %}#全局顶部导航
{% endblock %}
<!-- END Header -->
{% block nav-breadcrumbs %}
{% block breadcrumbs %}
{% endblock %}
{% endblock %}#面包屑
{%%20endif %}
{%%20if not is_popup and is_nav_sidebar_enabled %}
{% block nav-sidebar %}
{%%20include "admin/nav_sidebar.html" %}
{% endblock %}
{%%20endif %}#左侧菜单
{% block messages %}
{%%20if messages %}
{%%20endif %}
{% endblock messages %}#站点消息提醒
{% block pretitle %}{% endblock %}
{% block content_title %}{%%20if title %}<h1>{{ title }}</h1>{%%20endif %}{% endblock %}
{% block content_subtitle %}{%%20if subtitle %}<h2>{{ subtitle }}</h2>{%%20endif %}{% endblock %}
{% block content %}
{% block object-tools %}{% endblock %}#对象工具
{% endblock %}
{% block sidebar %}{% endblock %}#右侧列表
<!-- END Content -->
{% block footer %}<div id="footer"></div>{% endblock %}#页脚
掌握了上述代码的逻辑及修改位置,Django admin默认模板的修改就可以得心应上,将网站后台改为你想要的样子。
THE END