如何在 Tornado 中设置静态路径?

Eru*_*ang 2 python tornado python-3.x

我想设置我的http服务器的静态目录,并在其中放一些图片,以便用户可以使用url获取我的图片。但我失败了,下面的代码不起作用:

# ????
STATIC_DIRNAME = "resources"
# ??static path
settings = {
    "static_path": os.path.join(os.path.dirname(__file__), STATIC_DIRNAME),
}

# and I passed settings to Application
app = tornado.web.Application([
    (r"/pictures", handler.PicturesHandler),
], **settings)
Run Code Online (Sandbox Code Playgroud)

如何将静态目录设置为“资源”?

(我想通过如URL,让我的图片:localhost:8888/resources/1.jpg

Ser*_*aev 5

使用static_url_prefix

settings = {
    "static_path": os.path.join(os.path.dirname(__file__), STATIC_DIRNAME),
    "static_url_prefix": "/resources/",
}
Run Code Online (Sandbox Code Playgroud)