shi*_*ino 32 python favicon static tornado
我在尝试这个:
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()
Run Code Online (Sandbox Code Playgroud)
但是它一直favicon.ico在我的static_path中提供服务(我在两个不同favicon.ico的路径中有两个不同的路径,如上所示,但我希望能够覆盖它中的那个static_path).
Not*_*fer 52
static_path从应用设置中删除.
然后设置你的处理程序:
handlers = [
(r'/(favicon\.ico)', tornado.web.StaticFileHandler, {'path': favicon_path_dir}),
(r'/static/(.*)', tornado.web.StaticFileHandler, {'path': static_path_dir}),
(r'/', WebHandler)
]
Run Code Online (Sandbox Code Playgroud)
您需要用括号括起favicon.ico并在正则表达式中转义句点.你的代码将成为
favicon_path = '/path/to/favicon.ico' # Actually the directory containing the favicon.ico file
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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45522 次 |
| 最近记录: |