回到顶部

CONTENTS

django 修改 favicon

一. 重定向 favicon 的 url

# urls.py

"""django2 URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import re_path  # favicon.ico
from django.conf.urls import include
from django.conf.urls.static import static
from django.conf import settings
from django.contrib.auth import views as auth_views
from django.views.generic.base import RedirectView  # favicon.ico

# favicon.ico
favicon_view = RedirectView.as_view(url='/static/images/favicon.ico', permanent=True)

# 定制站点头部和标题
admin.site.site_title = '博客后台管理系统'  # 站点标题
admin.site.site_header = '博客后台管理系统'  # 站点头部

urlpatterns = [
                  re_path(r'favicon\.ico$', favicon_view),  # favicon.ico
                  re_path(r'favicon\.png$', favicon_view),  # favicon.ico

                  path('admin/', admin.site.urls),
                  path(r'ckeditor/', include('ckeditor_uploader.urls')),

              ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \
              + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

二. 在 base.html 修改

{% load static %}

<link rel="shortcut icon" href="{% static 'images/favicon.ico' %}">

 

# favicon.ico

^_^
请喝咖啡 ×

前一篇: Nginx 不能访问 Django 静态文件的原因
下一篇: ckeditor 上传图片禁止生成缩略图