回到顶部

阅读目录

django 修改 favicon(站点配置 ico 、站点标签页配置小图标)

重定向 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(re_path='/static/images/zhuo_64x64.ico', permanent=True)  # django1.11
favicon_view = RedirectView.as_view(url='/static/images/zhuo_64x64.ico', permanent=True)  # django2.2

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

urlpatterns = [
                  re_path(r'favicon\.[ico|png]$', 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

png 转 ico

http://www.easyicon.net/covert/

^_^
请喝咖啡 ×

文章部分资料可能来源于网络,如有侵权请告知删除。谢谢!

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