Python 如何在龙卷风中设置静态路径?
我想设置http服务器的静态目录,并在其中放置一些图片,以便用户可以使用url获取我的图片。但我失败了,下面的代码不起作用:Python 如何在龙卷风中设置静态路径?,python,python-3.x,tornado,Python,Python 3.x,Tornado,我想设置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
# 静态路径
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)
如何将静态目录设置为“资源”
(我想通过url获取图片,例如:localhost:8888/resources/1.jpg
)使用
解决了我的问题!非常感谢。您能告诉我为什么吗?@ErumHuang请查看您可以通过发送静态路径设置作为关键字参数来提供静态文件的文档。我们将从/static/URI(可通过static\u url\u前缀设置配置)提供这些文件,并从同一目录提供/favicon.ico和/robots.txt。
settings = {
"static_path": os.path.join(os.path.dirname(__file__), STATIC_DIRNAME),
"static_url_prefix": "/resources/",
}