如果你随处都有基本模板或标头模板,为什么不在基本HTML中添加收藏夹图标呢?
<link rel="shortcut icon" type="image/png" href="{% static 'favicon.ico' %}"/>
一种轻巧的技巧是在urls.py
文件中进行重定向,例如,添加如下视图:
from django.views.generic.base import RedirectView
favicon_view = RedirectView.as_view(url='/static/favicon.ico', permanent=True)
urlpatterns = [
...
re_path(r'^favicon\.ico$', favicon_view),
...
]
当你确实没有其他静态内容要托管时,这很容易使网站图标正常工作。