web.py设置favicon.ico的方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zgyulongfei/article/details/48196667

本文介绍在web.py中设置favicon.ico的方法:

如果没设置favicon,后台日志是这样的:

127.0.0.1:4133 - - [03/Sep/2015 18:49:53] "HTTP/1.1 GET /favicon.ico" - 303 See Other


由于浏览器会自动去获取这个文件,在web.py中可以这样设置:

设置步骤:

0、把favicon.ico图标拷贝到staic目录下,我这里是放在/static/res/目录下

1、在urls中添加映射规则:

urls = (
        '/', 'Index',
        '/favicon.ico','Icon',
        )


2、编写Icon类:

class Icon:
    def GET(self): 
        raise web.seeother("/static/res/favicon.ico")


3、效果:

127.0.0.1:4427 - - [03/Sep/2015 18:58:49] "HTTP/1.1 GET /favicon.ico" - 303 See Other
127.0.0.1:4427 - - [03/Sep/2015 18:58:49] "HTTP/1.1 GET /static/res/favicon.ico"  - 200


---------------------

转载请注明出处!

原文地址:http://blog.csdn.net/zgyulongfei/article/details/48196667

猜你喜欢

转载自blog.csdn.net/zgyulongfei/article/details/48196667