11

When running a web.py application with the development server, how do you get rid of the 404 error for the favicon?

"HTTP/1.1 GET /" - 200 OK
"HTTP/1.1 GET /favicon.ico" - 404 Not Found

Everything I've been able to find about eliminating this error has to do with specifying a path to the resource in your Apache configuration. This obviously doesn't help with the development server use case. Is there a way to specify static resources in the urls tuple? Can you define a document root in the web.py application?

tponthieux
  • 1,502
  • 5
  • 18
  • 30

4 Answers4

7

Like Ryan Griggs suggested, but use /static/favicon.ico as href.

<html>
<head>
    <link rel="icon" type="image/png" href="/static/favicon.ico">
    ...

web.py dev server maps all /static/ URLs to files in static/ directory.

Anand Chitipothu
  • 4,167
  • 4
  • 24
  • 26
5

The web.py API documentation references a 'web.seeother()' function which generates a
'303 SEE OTHER' response, redirecting a browser to a different location.
(See http://webpy.org/docs/0.3/api#web.application)

This is a server-side solution which doesn't require header changes in html files; particularly useful if the server isn't actually dealing with html files.

Solution:

Map a url route from the default /favicon.ico and create a new class to handle this route:

# Define API Routes
urls = (
    '/', 'index',
    '/favicon.ico', 'icon'
)

Create a (web accessible) static directory containing the favicon.ico

Create a new class to handle this file:

# Process favicon.ico requests
class icon:
    def GET(self): raise web.seeother("/static/favicon.ico")

Here are my server logs showing the requests:

<ip#> - [18/Oct/2013 21:54:54] "HTTP/1.1 GET /favicon.ico" - 303 See Other
<ip#> - [18/Oct/2013 21:54:54] "HTTP/1.1 GET /static/favicon.ico" - 200
<ip#> - [18/Oct/2013 22:03:02] "HTTP/1.1 GET /favicon.ico" - 303 See Other
<ip#> - [18/Oct/2013 22:03:03] "HTTP/1.1 GET /static/favicon.ico" - 304 Not Modified
xycmu
  • 66
  • 1
  • 4
2

Browsers automatically look for the /favicon.ico file in your website's root directory. This error simply means that the file 'favicon.ico' doesnt't exist. Simply create an icon file (or download one from one of the many favicon creator sites) and place it in your website's root web directory (public_html, etc).

For a better solution, edit your webpages' HTML to include a specific link to a favicon file:

<html>
<head>
    <link rel="icon" type="image/png" href="http://example.com/myicon.png">
    ...

See http://www.w3.org/2005/10/howto-favicon

Ryan Griggs
  • 2,457
  • 2
  • 35
  • 58
  • I seem to recall somewhere than some versions of IE required `rel="shortcut icon"` - but can't seem to find it again – Jon Clements Jul 24 '12 at 16:59
  • 1
    I have a favicon, it's in the project root right next to the application code. I've tried moving it around to various places in the project like /static, but I still get the error. The problem is that the web.py development server doesn't know where to find it, and I don't know how to tell it where to look. – tponthieux Jul 24 '12 at 21:00
1

Since web.py limits you to work only with the /static path for your static data, there is not really a way to correctly serve the favicon with the dev server. The best way to get rid of the 404 log is simply to add a url handler in the mapping:

urls = ("/favicon.ico", "dummy")

and in the dummy handler just pass an empty 200 response.

vonPetrushev
  • 5,457
  • 6
  • 39
  • 51