使用配置有 StaticFileHandler 的 BokehTornado 实例的独立散景服务器不显示图像

Image not showing with a standalone bokeh server using BokehTornado instance configured with StaticFileHandler

这是我之前 的跟进。

文件结构如下所示。我必须使用顶级目录中的 python -m bokeh_module.bokeh_sub_module 运行 脚本。 image.png 稍后可能来自任意目录。

.
├── other_module
│   ├── __init__.py
│   └── other_sub_module.py
├── bokeh_module
│   ├── __init__.py
│   ├── image.png # not showing
│   └── bokeh_sub_module.py
└── image.png # not showing either

bokeh_sub_module.py正在使用独立的散景服务器。但是,无论放置在何处,图像都不会显示。我收到这个 WARNING:tornado.access:404 GET /favicon.ico (::1) 0.50ms 我不确定这是散景还是龙卷风的问题。感谢您的帮助。

from other_module import other_sub_module
import os
from bokeh.server.server import Server
from bokeh.layouts import column
from bokeh.plotting import figure, show
import tornado.web

def make_document(doc):
    def update():
        pass

    # do something with other_sub_module
    p = figure(match_aspect=True)
    p.image_url( ['file://image.png'], 0, 0, 1, 1)
    doc.add_root(column(p, sizing_mode='stretch_both'))
    doc.add_periodic_callback(callback=update, period_milliseconds=1000)


apps = {'/': make_document}
application = tornado.web.Application([(r"/(.*)", \
                                      tornado.web.StaticFileHandler, \
                                      {"path": os.path.dirname(__file__)}),])
server = Server(apps, tornado_app=application)
server.start()
server.io_loop.add_callback(server.show, "/")
server.io_loop.start()

我试过参数extra_patterns,但它也不起作用...

您不能将 file:// 协议用于 Web 服务器和浏览器。只需使用常规 http://https://。如果您指定了正确的 URL,StaticFileHandler 应该会正确处理它。

除此之外,您对 Server 的用法不正确。它没有 tornado_app 参数。相反,直接传递路线:

extra_patterns = [(r"/(.*)", tornado.web.StaticFileHandler,
                   {"path": os.path.dirname(__file__)})]
server = Server(apps, extra_patterns=extra_patterns)

顺便说一句,以防万一 - 通常,您不应该提供应用程序的根目录。否则,任何人都可以看到您的源代码。