您的位置:首页 > 教育 > 锐评 > 8、Django Admin后台中添加Logo

8、Django Admin后台中添加Logo

2024/10/6 10:32:32 来源:https://blog.csdn.net/netandghost/article/details/141751713  浏览:    关键词:8、Django Admin后台中添加Logo

在项目settings.py文件

# 导入os,并且修改'DIRS'内容如下所示
import os
TEMPLATES = [{'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': [os.path.join(BASE_DIR, 'templates/')],'APP_DIRS': True,'OPTIONS': {'context_processors': ['django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',],},},
]

找到django项目中的模板文件,路径中包括django\contrib\admin\templates\admin,我的文件是在

E:\Django\study\20240828\venv\Lib\site-packages\django\contrib\admin\templates\admin

找到base_site.html复制到项目目录templates\admin,添加LOGO的文件

所增加的文件及路径如下所示:

修改base_site.html,我这里注释掉原代码,添加了以下h1标签代码

{% extends "admin/base.html" %}{% block title %}{% if subtitle %}{{ subtitle }} | {% endif %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}{% block branding %}{% comment %} <h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Django administration') }}</a></h1> {% endcomment %}<h1 id="site-name"><a href="{% url 'admin:index' %}"><img src="/static/images/head.jpg" alt="Your Site Logo" height="50px">我的管理网站</a></h1>
{% endblock %}{% block nav-global %}{% endblock %}

显示效果:

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com