favicon.ico

1,362 views
Skip to first unread message

voxtreet

unread,
Sep 23, 2011, 6:45:13 PM9/23/11
to web.py
Hi,

Just started using web.py, wrote my first web service in less than 10
lines, so THANK YOU!

My question is about the favicon.ico file. I built the web app from
the tutorial, and run it directly from Python using the web.py built-
in web server. Every time I access the web service from a browser
(Chrome on Mac), I see in the logs a GET request for the URL I typed
in, but also see a GET request for /favicon.ico, to which my server
responds with a 404 Not Found error.

It's not a problem, but it is an annoyance. When I deploy this to
Apache, I will get an extra line in my error logs every time someone
visits from a browser.

I know this is a browser-specific issue (trying to find the icon to
put in the address bar), so not a big deal if requests are coming
directly from web apps. And I'm sure I could come up with some image
and install a favicon.ico somewhere and get web.py to serve it up. But
I'm just wondering if there is some way that web.py can "ignore" these
requests, or rather, not result in so many 404 errors in my logs? E.g.
some sort of built-in/default url mapping to some blank .ico data that
comes with web.py, or something like that?

Thanks!

Bruce Eckel

unread,
Sep 24, 2011, 1:27:32 AM9/24/11
to we...@googlegroups.com
I too am curious about this one -- is there some command or code so that Web.py could serve favicon.ico?

-- Bruce Eckel
www.Reinventing-Business.com
www.MindviewInc.com




--
You received this message because you are subscribed to the Google Groups "web.py" group.
To post to this group, send email to we...@googlegroups.com.
To unsubscribe from this group, send email to webpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webpy?hl=en.


andrei

unread,
Sep 25, 2011, 4:40:11 AM9/25/11
to web.py

Just add <link rel="shortcut icon" href="/static/favicon.ico"
type="image/x-icon"> in the <head> section of your base template and
put favicon.ico in your static folder.

Oscar Ciudad

unread,
Nov 10, 2011, 6:25:27 PM11/10/11
to web.py
A fairly simple solution, not having to put any header HTML header.
favicon.ico is supposed to exist under "static":

import web

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

app = web.application (urls, globals())

class favicon:
def GET(self):
f = open("static/favicon.ico", 'rb')
return f.read()

if __name__ == "__main__": app.run()

andrei

unread,
Nov 11, 2011, 11:09:54 AM11/11/11
to web.py

Or setting alias in apache config when in production. I don't think
streaming favicon through webpy is a good idea.

And your example needs proper content type header.

Oscar Ciudad

unread,
Nov 20, 2011, 5:34:22 PM11/20/11
to web.py
You're right. I just missed a line before "return f.read()":

web.header("Content-Type","image/x-icon")

Sure this is not the optimal solution for production, it just answers
the question made by Bruce Eckel, favicon is served entirely by
web.py, no matter if under Apache or not, and is also valid even in
cases in which you are not serving HTML pages.

Thank you!

Alex Stankovic

unread,
Sep 4, 2012, 2:23:19 PM9/4/12
to we...@googlegroups.com
I realize this is an old post but just to provide another alternative.

Place the favicon.icon in the static folder, then

import web 

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

app = web.application (urls, globals()) 

class favicon:
def GET(self):
raise web.seeother('/static/images/favicon.ico')

if __name__ == "__main__": app.run() 

Avoids adding config to Apache (easy to forget if you move servers) and avoids streaming by web.py. The downside, though, is that the browser gets a 303 redirect on first request.

Andrey Kuzmin

unread,
Sep 5, 2012, 4:37:14 PM9/5/12
to we...@googlegroups.com
Nice way, but raising permanent redirect instead of seeother would be better.

I.e. raise web.redirect instead of web.seeother.
Reply all
Reply to author
Forward
0 new messages