我应该把 `favicon.ico` 放在哪里,以便 bokeh serve 可以找到并渲染它?

Where should I put `favicon.ico` so bokeh serve can find and render it?

我有一个 directory format 应用程序,名为 myapp,例如:

myapp/
   |
   + -- main.py
   + -- favicon.ico
   + -- static
           |
           + -- some.img

如果我 运行 bokeh serve myapp,我会不断得到 404 GET /favicon.ico (::1)

我应该把favicon.ico放在哪里?

现在,没有简单的方法可以用 bokeh servefavicon.ico 服务。如果你真的需要 favicon.ico,在我看来,最直接的方法就是从 bokeh serve 切换到 Tornado 应用程序,就像在 the example 中一样。它更加灵活,不需要那么多配置。

您可以在 templates 目录下将 HTML 模板添加到 Bokeh 应用程序。这样,您就可以在模板的 <head> 中以正常方式指定网站图标位置。有关使用模板的应用示例,请参阅 GitHub 存储库中的 the crossfilter demo

模板只需要

{{ plot_div }}
{{ plot_script }}

<body>。该应用程序会在 plot_div 所在的任何位置呈现。

创建文件夹 "templates" 并添加 "index.html" 和

{% extends base %}

{% block preamble %}
<link rel="icon" type="image/x-icon" href="myapp/static/favicon.ico">
{% endblock %}

并将您的 "favicon.ico" 移动到文件夹 "static" 中。 所以你有:

myapp/
   |
   + -- main.py
   + -- templates
           |
           + -- index.html
   + -- static
           |
           + -- favicon.ico

这里有一些关于扩展散景模板的更多信息。 https://docs.bokeh.org/en/latest/docs/user_guide/embed.html#standard-template

还要感谢 bigreddot 的回答和 gepcel 的有用评论。