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 %}

显示效果:

相关推荐
好奇的菜鸟2 小时前
如何在IntelliJ IDEA中设置数据库连接全局共享
java·数据库·intellij-idea
tan180°2 小时前
MySQL表的操作(3)
linux·数据库·c++·vscode·后端·mysql
满昕欢喜3 小时前
SQL Server从入门到项目实践(超值版)读书笔记 20
数据库·sql·sqlserver
Hello.Reader4 小时前
Redis 延迟排查与优化全攻略
数据库·redis·缓存
简佐义的博客5 小时前
破解非模式物种GO/KEGG注释难题
开发语言·数据库·后端·oracle·golang
爬山算法5 小时前
MySQL(116)如何监控负载均衡状态?
数据库·mysql·负载均衡
老纪的技术唠嗑局7 小时前
OceanBase PoC 经验总结(二)—— AP 业务
数据库
阿里云大数据AI技术8 小时前
OpenSearch 视频 RAG 实践
数据库·人工智能·llm
m0_6239556610 小时前
Oracle使用SQL一次性向表中插入多行数据
数据库·sql·oracle
阿蒙Amon11 小时前
C#读写文件:多种方式详解
开发语言·数据库·c#