how to get favicon.ico work on tornado

ぐ巨炮叔叔 提交于 2019-12-12 13:40:43

问题


the tornado server didn't do the favicon.ico by default,so i always get the info like these

[W 130626 10:38:16 web:1514] 404 GET /favicon.ico (192.168.1.57) 0.57ms

i use the web.staticfilehandler in various way include the source's example,and couldn't get it work, i got things work like this below.

handlers = [
    (r'/favicon.ico', tornado.web.StaticFileHandler,dict(url='/static/favicon.ico',permanent=False)),
    (r'/static/(.*)', tornado.web.StaticFileHandler, {"path": "plserver"}),
 ]

i felt so dump,i have to redirect it and couldn't sure it will work on web page in real world.


回答1:


And I changed it to this one, this time I've got what I want

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

I got the answer while i wrote the post.




回答2:


I put the favicon.ico in the .\static\, and add following code to html.

<link rel="shortcut icon" href="{{ static_url('favicon.ico') }}">

it would be generated like this:

<link rel="shortcut icon" href="/static/favicon.ico?v=bb3f1">

That's all.



来源:https://stackoverflow.com/questions/17311084/how-to-get-favicon-ico-work-on-tornado

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!