Django admin后台默认模板文件解读
admin的默认模板位于django/contrib/admin/templates/admin/文件下,文件结构接对应解读说明如下:
auth/useradd_form.htmlchange_password.htmledit_inlinestacked.htmltabular.htmlincludesfieldset.htmlobject_delete_summary.htmlwidgetsclearable_file_input.htmldate.htmlforeign_key_raw_id.htmlmany_to_many_raw_id.htmlradio.htmlrelated_widget_wrapper.htmlsplit_datetime.htmltime.htmlurl.html404.html500.htmlactions.htmlapp_index.htmlapp_list.htmlbase.htmlbase_site.htmlchange_form.htmlchange_form_object_tools.htmlchange_list.htmlchange_list_object_tools.htmlchange_list_results.htmlcolor_theme_toggle.htmldate_hierarchy.htmldelete_confirmation.htmldelete_selected_confirmation.htmlfilter.htmlindex.htmlinvalid_setup.htmllogin.htmlnav_sidebar.htmlobject_history.htmlpagination.htmlpopup_response.htmlprepopulated_fields_js.htmlsearch_form.htmlsubmit_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




