这是我之前question的后续版本。
文件的结构如下所示。我必须使用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 eitherbokeh_sub_module.py正在使用独立的bokeh服务器。但是,无论放置在何处,图像都不会显示。我得到了这个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,但它也不起作用...
发布于 2020-07-07 22:39:46
您不能在web服务器和浏览器中使用file://协议。只需使用常规的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)顺便说一句,以防万一--一般来说,你不应该服务于你的应用的根目录。否则,任何人都可以看到您的源代码。
https://stackoverflow.com/questions/62766797
复制相似问题