gpt4 book ai didi

python - 如何从与静态路径不同的目录提供静态文件?

转载 作者:IT老高 更新时间:2023-10-28 21:59:55 26 4
gpt4 key购买 nike

我正在尝试这个:

favicon_path = '/path/to/favicon.ico'

settings = {'debug': True,
'static_path': os.path.join(PATH, 'static')}

handlers = [(r'/', WebHandler),
(r'/favicon.ico', tornado.web.StaticFileHandler, {'path': favicon_path})]

application = tornado.web.Application(handlers, **settings)
application.listen(port)
tornado.ioloop.IOLoop.instance().start()

但它一直为我的 static_path 中的 favicon.ico 提供服务(我在两个单独的路径中有两个不同的 favicon.ico,如上所述,但我希望能够覆盖 static_path 中的那个)。

最佳答案

删除static_path从应用设置。

然后将您的处理程序设置为:

handlers = [
(r'/(favicon\.ico)', tornado.web.StaticFileHandler, {'path': favicon_path_dir}),
(r'/static/(.*)', tornado.web.StaticFileHandler, {'path': static_path_dir}),
(r'/', WebHandler)
]

关于python - 如何从与静态路径不同的目录提供静态文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10165665/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com