为什么网站图标没有出现在生产环境中?

Why isn't favicon shown up in production?

尽管 Django 的响应代码为 200,但选项卡中未显示 Favicon。静态文件位于 'myproject/build'('settings.py' 位于 'myproject/server',应用程序位于 'myproject/blog').尽管带有 css 和 js 文件的 HTML 页面运行良好。并且 'favicon.ico' 与 'index.html' 页面

位于同一目录中

我试图在开发人员选项中通过 "localhost:8000' address in different browsers and I got the same thing: favicon isn't shown up in the tab. I also looked at "Sources" 打开一个页面:没有任何 'favicon.ico' 文件

settings.py :

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'build/static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

urls.py(在'server/'):

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('blog.api.urls')),
    re_path('.*', TemplateView.as_view(template_name='index.html'))
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

index.html(在'build/'):

<link rel="shortcut icon" href="/favicon.ico" />

控制台:

[10/Jun/2019 09:57:29] "GET /favicon.ico HTTP/1.1" 200 2242

UPD:我 运行 命令 python manage.py collectstatic 但我仍然遇到与 favicon

相同的问题

您的 favicon 位于静态文件夹中:

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